Author
String split on multiple regex
Harry Steinke
Greenhorn
Joined: Dec 09, 2005
Posts: 13
posted Dec 09, 2005 10:29:00
0
I have some text that I wish to parse but there are 2 different characters (, and |) I want to parse it on ex. some text, with | extra , things in it Is there a way to do this split once or would I have to do 2 separate splits String [] split = s.split(","); String[] split2 = split.split("\\|");
Joel McNary
Bartender
Joined: Aug 20, 2001
Posts: 1815
See Regualr Expressions . Since the split method takes a regular expression, you can say: Which means: Split the string on the ',' or '|' characters. (Note that the vertical pipe is the OR operator in regular expressions.)
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Harry Steinke
Greenhorn
Joined: Dec 09, 2005
Posts: 13
posted Dec 09, 2005 11:24:00
0
That did it. Thanks
subject: String split on multiple regex