Reputation: 33
I have a String, I need to split it with a comma, but if the previous character is \, then this part should not be splitted.
For example from String str = "first,second\\,third,fourth"
i need String[] strs = { "first", "second\\,third", "fourth" }
Upvotes: 1
Views: 116
Reputation: 43738
Something like this?
String str = "first,second\\,third,fourth";
String[] strs = s.split("(?<!\\\\),");
look at the java.utils.regex.Pattern documentation for an explanation.
Upvotes: 2