aspose file tools*
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
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30780
    
157

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: 39436
    
  28
I think the plus means "one or more occurrences of . . . "
 
Consider Paul's rocket mass heater.
 
subject: How to add multiple delimeters to a regular expression?