This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String split on multiple regex Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String split on multiple regex" Watch "String split on multiple regex" New topic
Author

String split on multiple regex

Harry Steinke
Greenhorn

Joined: Dec 09, 2005
Posts: 13
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: 1817

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
That did it.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String split on multiple regex
 
Similar Threads
Getting user input using Swing
Parsing
String - Remove dashes from text
plz delete
Parsing Strings