I am trying to split a string on white spaces only (\s
), but that are not between a "quoted" section.
I am matching all text in between these quoted sections in the following manner:
(['"`]).*?\1
Regex101
However, when I try to add this as a negative lookahead, to only split on white spaces outside of those quotes, I can't get it to work:
\s(?!(['"`]).*?\1)
Regex101
How can I only split on the white spaces that are not in "quotes"?
\s(?=(?:[^'"`]*(['"`])[^'"`]*\1)*[^'"`]*$)
You can use this regex with lookahead
to split upon.See demo.
https://regex101.com/r/5I209k/4
or if mixed tick types.
https://regex101.com/r/5I209k/7
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