Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

comparing strings

Thread view: 
manzur - 07 Mar 2006 06:16 GMT
how do i know that the string which i have is in the my desired  format
.

My format is z:y:x
where z,x,y are integers.

thnx in advance
Bart Cremers - 07 Mar 2006 06:27 GMT
Use regular expressions.

Pattern patt = Pattern.compile("^\\d+:\\d+:\\d+$");
if (patt.matcher(input).matches()) {
   // Yay!!!
} else {
   // Boo
}

This code is not tested.

Regards,

Bart
hiwa - 07 Mar 2006 06:29 GMT
if (myString.matches("^\\d:\\d:\\d$")){
 ...
}
manzur - 07 Mar 2006 07:34 GMT
Greedy quantifiers
X? X, once or not at all
X* X, zero or more times
X+ X, one or more times
X{n} X, exactly n times
X{n,} X, at least n times
X{n,m} X, at least n but not more than m times

Reluctant quantifiers
X?? X, once or not at all
X*? X, zero or more times
X+? X, one or more times
X{n}? X, exactly n times
X{n,}? X, at least n times
X{n,m}? X, at least n but not more than m times

Possessive quantifiers
X?+ X, once or not at all
X*+ X, zero or more times
X++ X, one or more times
X{n}+ X, exactly n times
X{n,}+ X, at least n times
X{n,m}+ X, at least n but not more than m times

cn any one expalin me wht is the difference between the above  three.
If some one can provide examples it would be great help
thnx in advance
Roedy Green - 07 Mar 2006 07:43 GMT
>cn any one expalin me wht is the difference between the above  three.

see http://mindprod.com/jgloss/regex.html

Sometime words fail. You need to write yourself a little test program
and feed it strings and see what it does.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

manzur - 07 Mar 2006 07:57 GMT
wht actually i want to know was :
In Greedy quantifiers the api says
X? X, once or not at all

In Reluctant quantifiers the api says

X?? X, once or not at all

I was not able to understand wht X means in the above two scenarious.
Jussi Piitulainen - 07 Mar 2006 08:23 GMT
> wht actually i want to know was :
> In Greedy quantifiers the api says
[quoted text clipped - 5 lines]
>
> I was not able to understand wht X means in the above two scenarious.

It stands for a regular expression. You can instantiate those
documentation lines with any old expression you want, as long as its
bound tight enough with respect to the quantifier.

[^_^]?      matches [^_^] once or not at all
(<maybe>)?  matches <maybe> once or not at all

X? stands for both of these, and many more.

<maybe>?    matches <maybe and then > once or not at all

Here X? stands for >?.
hiwa - 07 Mar 2006 09:00 GMT
Good read for regex novice:
http://java.sun.com/docs/books/tutorial/extra/regex/index.html
Differences Among Greedy, Reluctant, and Possessive Quantifiers
http://java.sun.com/docs/books/tutorial/extra/regex/quant.html
Roedy Green - 07 Mar 2006 17:05 GMT
>I was not able to understand wht X means in the above two scenarious.

Did you read the link I gave you?
Did you do write an experimenting regex class?
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.