Reputation: 77
I have a string that I am using String.split(regex) to eventually get a string[].
The string format is
January,WEEKDAY,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,AJanuary,WEEKEND,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,B,B,BJanuary,HOLIDAY,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,C,C,CFebruary,WEEKDAY,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,AFebruary,WEEKEND,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,B,B,BFebruary,HOLIDAY,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,AMarch,WEEKDAY,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,C,C,C
The first string after the split should be
January,WEEKDAY,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A
So I'm thinking I need to do a split at either ,A or ,B or ,C that is not followed by a ,
To test the first one, I tried making my regex "(?<!,)A,"
but that didn't work
Any ideas?
Upvotes: 2
Views: 257
Reputation: 70732
It seems you're looking for something like the following:
String[] parts = s.split("(?<=,[ABC](?!,))");
Or you can use a word/non-word boundary here as well:
String[] parts = s.split("(?<=\\b[ABC]\\B)");
Upvotes: 1