I have the following method, where I want the regex given to the split method to find all instances of the comma character (“,”), if if is not preceded by letter “x”.
The method:
public void replaceTest3() {
String valueRaw = "onex,two,three,fourx,five";
String[] splittedString = valueRaw.split("[(.,)]&&[^x{1}+,]");
for (int i = 0; i < splittedString.length; i++) {
System.out.println(splittedString[i]);
}
}
So I would expect this method to output
onex,two
three
fourx,five
However, as the regex currently is, the latter part to exclude all instances of commas preceded by "x" doesn't work - apparently nothing is found. Where is my error and how could I achieve what I want to do?
Could be done with a negative lookbehind like this:
I.e: