I have some troubles with this regular expression in javascript. That same regex works in PHP, but in JavaScript this error occurs: “Invalid regular expression: unrecognized character after (?”. My regular expression is:
text = text.replace(/(?<!\=\")http([A-Za-z0-9:\/\.\+\?\%\@\!\#\&_-]+)/g,
'<a href="http$1" target="_blank" rel="nofollow">http$1</a> ');
The problem is in first part (?< !\=\") but I don’t know how to solve it because it is a normal regular expression for PHP or C.
Is there any analog of this construction? I need to disallow symbol " (double quotes) right before “http” for preventing url replacements in html elements like <img>.
I’m edit the question because the symbols < plus ! make an error in displaying text after it. (that, may also invoke error).
In your example above (including adding the ):
This would work for you:
And outputs:
Basically it recognizes the url by anything not a space in front of a
.com/plus anything afterwards not a space. It won’t grab the<img src="img.com" />as that’s a.com".If you only have .com domains this will work, if you have .net, .org, etc, etc. then you’ll have to add those as things to check.