Reputation: 11822
function fuzzQuery(rawQuery)
{
re = /(?=[\(\) ])|(?<=[\(\) ])/;
strSplit = rawQuery.split(re);
alert(strSplit);
};
Does not work (no dialog box).
I've check the expression at http://rubular.com/ and it works as intended.
Whereas
re = /e/
does work.
The input string is
hello:(world one two three)
The expected result is:
hello:,(,world, ,one, ,two, ,three, )
I have looked at the following SO questions:
Javascript simple regexp doesn't work
Why this javascript regex doesn't work?
But I'm not making the mistakes like creating the expression as a string, or not double backslashing when it is a string.
Upvotes: 2
Views: 190
Reputation: 70732
Well the main issue with your regular expression is that javascript does not support Lookbehind.
re = /(?=[\(\) ])|(?<=[\(\) ])/
^^^ A problem...
Instead, you could possibly use an alternative:
re = /(?=[() ])|(?=[^\W])\b/;
strSplit = rawQuery.split(re);
console.log(strSplit);
// [ 'hello:', '(', 'world', ' ', 'one', ' ', 'two', ' ', 'three', ')' ]
Upvotes: 4
Reputation: 4864
You can use something like this :
re = /((?=\(\) ))|((?=[\(\) ]))./;
strSplit = rawQuery.split(re);
console.log(strSplit);
Upvotes: 0