• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular expression

 
Marilyn Monickam
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Using the javax.util regex package' Pattern matcher is it possible to write a Pattern to check if a string does not contain two or more consecutive hyphens or spaces
Thanks
Marilyn
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah - but it seems much easier to check if it does contain two consecutive hyphens or spaces, and interpret the result of find() accordingly.
 
Marilyn Monickam
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jim
Is there a method available that can return the pattern if I give a string?

Marilyn
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um, in one sense, that's what Pattern.compile() does - creates Pattern object based on an input string which represents that pattern. But I don't know if that's what you mean. If you mean, is there a method that will tell me to use " |--" in this situation, then no, not really. You have to read the documentation for the java.util.regex.Pattern class. And/or spend time with a good book like O'Reilly's Mastering Regular Expressions. Or just practice a lot.
 
Marilyn Monickam
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its the second thing I wanted to know "if there is a method that will tell me to use " |--" in this situation ". Will have to try a lot of combinations now :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic