I need to split a string passing a regex, but the split token is just the group 1 of the regex. An example:
Original String = "paulo\\;Is\\;In;Real;Doubt"
Array formed using the split = ["paulo\\;Is\\;In", "Real", "Doubt"]
My first idea was to use as regex: [^\\\\][;] but it obviously did not work.
The output was: ["paulo\\;Is\\;I", "Rea", "Doubt"] (I am using the String.split() method.)
My second idea was to use the ; as a group: [^\\\\]([;]), but I just can’t tell the split method to just consider the group(1) as a split token.
Your question is hard to answer because it is entirely unclear. You say your split token is “just the group 1 of the regex”. Group 1 of what regex?
EDIT: Still hard to answer, why don’t you clarify?
Anyway, if what you want is “split on ‘;’, but only when it’s not escaped with a ‘\'”, then you can use negative lookbehind to get what you want.
Example:
gives