0

I have this exactly specific requirement, Regex split string preserving quotes

but in JavaScript.

research library "not available" author:"Bernard Shaw"

to

research

library

"not available"

author:"Bernard Shaw"

I guess js does not support positive lookbehind (googled it :) ). I am not able to do it cleanly in js. Any help will be really great as am not much aware of regex.

Thanks in advance.

Community
  • 1
  • 1

1 Answers1

0

Worked for me. May be you are missing something.

I tried the following code and it worked fine:

<html>
<script type="text/javascript">
    var str = 'single words "fixed string of words"';
    var split_str = str.match(/\w+|"[^"]+"/g)
    alert(split_str[0]);
    alert(split_str[1]);
    alert(split_str[2]);
</script>
</html>
Sumedh Sidhaye
  • 299
  • 1
  • 4
  • 14