I have a string like this String str = "la$le\\$li$lo".
I want to split it to get the following output "la","le\\$li","lo". The \$ is a $ escaped so it should be left in the output.
But when I do str.split("[^\\\\]\\$") y get "l","le\\$l","lo".
From what I get my regex is matching a$ and i$ and removing then. Any idea of how to get my characters back?
Thanks
Use zero-width matching assertions:
The regex is essentially
It uses negative lookbehind to assert that there is not a preceding
\.See also
More examples of splitting on assertions
Simple sentence splitting, keeping punctuation marks:
Splitting a long string into fixed-length parts, using
\GUsing a lookbehind/lookahead combo:
Related questions