• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regular Expression string format check.

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i want to use regular expression for my application. I have some kind of string which i am reading from console and after reading i have to check the parameters of that string like e.x

YOU:ME 3,OTHERS 4,EVERYONE 5
So after reading from the console i have string "YOU:ME 3,OTHERS 4,EVERYONE 5" but now from this string i want to check the ranges for ME, OTHERS and EVERYONE (suppose iset range for ME 0-5, OTHERS 0-9 etc.) and also the pattern of the string suppose if someone enter pattern "YOU:My 3,OTHrtrERS 4,EVERYONE 5" on screen i will verify if this is the correct format of string as defined above or not.
Can anyone help me here???
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

have a look at http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html

Also your code should look something like this

if ( Pattern.matches("YOU:ME [1-3], OTHERS [0-9], EVERYONE [0-5]",
"YOU:ME 3, OTHERS 4, EVERYONE 5"))
{
System.out.println("Matches");
}
else
{
System.out.println("Does Not Match");
}

However this will only match on the correct spacing and lettering ( CAPS )
 
machines help you to do more, but experience less. Experience this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic