Reputation: 127
I have been stucked with this problem for hours. I have a regex pattern and a matching string. Regarding to regex101.com, it is sure a matching string, but in my script, regarding to JSFiddle, it doesn't match.
RegExp: /\[img=?.*?http:\/\/lorempixel\.com\/640\/480.*?\/img\]/
String to match: [img=http://lorempixel.com/640/480]description[/img]
Script: JSFiddle
Can anyone find the problem here?
Upvotes: 0
Views: 1759
Reputation: 191829
You can't concatenate a regex using a regex literal, and you need a regex for the .match
method.
var regex = new RegExp("\\[img=?.*?" + regexSafeUrl + ".*?\/img\\]");
EDIT: James Montague is correct that .match
will implicitly use a RegExp. You don't need the /
in the string that gets converted to RegExp though or these will be considered literal slashes. Your real problem was doing this as well as not properly escaping in the string.
Upvotes: 2