I'm trying to split a test String, "1 + 2 = 3 += 4 + --5" into its components without relying on spaces. I want the end result to be { 1, +, 2, =, 3, +=, 4, +, --, 5 } however some tokens seem to stick together. I wrote the following Regex to split the String:
"(?<=(\\.)|(\\w))\\s*(?=[O])|(?<=[O])\\s*(?=(\\.)|(\\w))"
and then used the ReplaceAll function to replace "O" with the following, which are my operators that I want to split on:
"(\\\\+)|(\\\\=)|(\\\\+=)|(\\\\-)"
However when applying this regex to splitting the String I provided as an example, I get the following result: { 1, +, 2, =, 3, +=, 4, +--, 5 }. Why do the minuses stick to the plus in the 2nd to last token? Is there anyway to fix this and make the split tokens appear as { 1, +, 2, =, 3, +=, 4, +, --, 5 }?