I am attempting to use regexes in jQuery, and I am running into some problems. This is the string that I am operating on:
NSLog(@"It works!");
I want the regex to select everything between the @” and the “, inclusive. This regex works just fine in Reggy, but when put in my JavaScript, does not work:
@".*"
My jQuery code is as follows in this section (is single-quotes the issue, perhaps?):
var regex='@".*"';
$(".syntaxhighlight").highlight(regex,'string');
I know the issue is not the highlight() function, because this works just fine:
$(".syntaxhighlight").highlight('nil','string');
So, how do I get this regex working properly?
The
highlight()feature usesString.indexOf()internally, which doesn’t support regular expression objects.However, it can be rewritten like so: