slevithan/xregexp

Error: Unbalanced delimiter found in string

vyushin opened this issue · 1 comments

XRegExp version: 4.4.0

I'm trying provide string with double quotes to matchRecursive method

const str = '"Hello, "World"!"';
XRegExp.matchRecursive(str, '"', '"', 'g');

this throws an error:

Error: Unbalanced delimiter found in string

The same case works with other symbols. For example:

const str = '{"hello": { "value": "world" }}';
XRegExp.matchRecursive(str, '{', '}', 'g') // Ok

How can I use matchRecursive to find matches in string containing double quotes?

XRegExp.matchRecursive in its current form doesn't work with identical left and right delimiters. That said, you can adapt your task so the positions your delimiters match are not identical with something like this:

const str = '"Hello, "World"!"';
XRegExp.matchRecursive(str, '"(?=\\w)', '"(?!\\w)', 'g');
// -> ['Hello, "World"!']