I posted this question a while back which was answered well:
Complex regex to split up a string
I know have a new conundrum related to it, and I'm really not getting anywhere...
Say I now have a string like this:
{foo.bar:/?a{3}}{blah}
Using the code supplied in the previous post it does this:
{foo.bar:/?a
{3}}
{blah}
I want it to do this:
{foo.bar:/?a{3}}
{blah}
This is because now I have to deal with strings that don't have an escape before the second curly brace in the example. I need some code that can spot when to ignore certain opening curly braces. Eg. If reading along the string from left to right it sees the first opening curly brace, then when it sees the second opening curly brace it kinda says 'hang on, I haven't seen a valid closing curly brace yet, so I am going to ignore this'. Is this possible? I understand that it may not entirely possible using purely regex.
This is the initial part of the code I am using from the previous question which is causing the issue:
var m = str.match(/{?(\.|[^{}])+}?/g);
Or another solution might be that when the user is typing & submitting the string beforehand, it slips in an escaping backslash without the user seeing it. The trouble with this is knowing which escaping backslashes to 'hide' again from the user...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…