Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add multiple delimeters to a regular expression?

 
vahid mirjamal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
vahid mirjamal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the plus means "one or more occurrences of . . . "
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic