I am trying to retrieve a part of a string from a URL using regex.exec()it but I am getting an error for some reason. Hoping you guys can spot it.
I am trying to get this from the string -> http://anotherdomain.com/image.jpg
var haystack = 'http://domain.com/?src=http://anotherdomain.com/image.jpg&h=300';
var needle = /(?<=src=).+(?=&h)/;
var results = needle.exec(haystack);
So on load I am getting this error -> SyntaxError: invalid quantifier
So I tried adding single quotes around the needle but didn’t work. Adding quotes gives me needle.exec is not a function.
Javascript regular expressions do not support lookbehind.
You might be able to get by with: