2
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?

Javascript regex not working

Javascript RegEx Not Working

But I'm not making the mistakes like creating the expression as a string, or not double backslashing when it is a string.

1

2 Answers 2

4

Well the main issue with your regular expression is that 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', ')' ]
Sign up to request clarification or add additional context in comments.

2 Comments

Lame. Any suggestions?
@dwjohnston I added a possible alternative.
0

You can use something like this :

re = /((?=\(\) ))|((?=[\(\) ]))./;    

    strSplit = rawQuery.split(re);

    console.log(strSplit);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.