• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Regular expression

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :-)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic