Does scriptable support positive lookbehind assertions?

Can’t get my code to work. I’ve tried everything I can think of. I’ve double checked my syntax. Heck probably checked 10 times!


var url_video = 'https://www.instagram.com/tv/B7hj-tUhNkt/?igshid=m04ih801dy9n'
var url_pic = 'https://www.instagram.com/p/B7jYI8oll8w/?igshid=11vpf4r072mvh'


let r = new Request(url_pic)
let body = await r.loadString()

Pasteboard.copy(body)

var re = new RegExp("(?<=(<meta property=\"og:image\" content=\"))(.*)(?=\")")

var test = re.test(body)
var match = body.match(re)

// let webview = new WebView()

// await webview.loadURL(url_pic)



console.log(match[0])

Error message


2020-03-01 16:13:54: Error on line 10:20: SyntaxError: Invalid regular expression: invalid group specifier name

1 Like

That’s really a question about Apple’s javascript engine. I don’t believe Scriptable has its own engine.

I wonder if the issue is the double quotes outside the expression. Does it work if you just do something like this?:

var re = /(?<=(<meta property=\"og:image\" content=\"))(.*)(?=\")/i;

I get the same issue. Seems it’s an issue with the javascript engine as mentioned by @Martin_Packer. I figured as much but it’s annoying when some regex will work on some engines and not on others because I can’t tell how to know before hand if it will work or not.

You could always just use capture groups to get the same effect.

You can see which things are supported by which browsers here:

Scroll most of the way down and you’ll see that Safari (and ie and firefox) do not support look-behind assertions.

Ended up just doing a string slice with counting the start of the piece of the link i want up to the length of the string. I knew this would work as I have done this before. Thanks for the help.