This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes How to add multiple delimeters to a regular expression? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to add multiple delimeters to a regular expression?" Watch "How to add multiple delimeters to a regular expression?" New topic
Author

How to add multiple delimeters to a regular expression?

vahid mirjamal
Greenhorn

Joined: Feb 24, 2009
Posts: 9
String tokens[] = essayInput.split("\\.");

How can i get that to also recognize the following:

a space, ! ? and .

I've been trying for hours, and only got the period to work.

Any ideas?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30352
    
150

Vahid,
If you put the character between braces, the special meaning doesn't apply. For example:
[ .?!]+

This matches one or more of a few special characters


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
vahid mirjamal
Greenhorn

Joined: Feb 24, 2009
Posts: 9
Thanks!
What's the plus for?

Also how do you get it to exclude extra spaces in between two words like if someone says : I like cake. it would count 3 spaces instead of 1. Any ideas?

Thanks
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
vahid mirjamal wrote:Thanks!
What's the plus for?

You might need to look at Regex
It's bit tedious.

And I read your first post but I couldn't understand your problem. Can you be little more clear?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38405
    
  23
I think the plus means "one or more occurrences of . . . "
 
wood burning stoves
 
subject: How to add multiple delimeters to a regular expression?