aspose file tools
The moose likes Java in General and the fly likes Regular Expression string format check. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Regular Expression string format check." Watch "Regular Expression string format check." New topic
Author

Regular Expression string format check.

Sanj Sharma
Ranch Hand

Joined: Feb 14, 2004
Posts: 32
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???
P Reen
Greenhorn

Joined: Jun 17, 2005
Posts: 2
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 )
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Regular Expression string format check.
 
Similar Threads
Cron expression issue
Searching a char[]
parsing a text file java and return a set of lines
Dobut in regex code
problem with regular expression for date formate