example string:
hello ! < and ! world>, and ! letter and [another ! letter] here.
Let's say, I want to split the sentence by ! character if it is not between < and >and also not between { and }.
I have been using :
str.split(/\!+(?=(?:(?:[^<]*"){2})*[^>]*$)/g);
to split if not between < and > , but how to add the another clause { and } too? Putting | doesnt solve, because it might then match blended < and }..
/!(?![^<]*>)(?![^{]*\})/g
!(?![^<]*>) matches a ! if it is not followed followed by a >, unless it is preceeded by a <. Gotten from this answer
Then simply chained with another negative lookahead for the second set of delimiters.
Demo here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With