comparing strings

M

manzur

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
 
B

Bart Cremers

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
 
M

manzur

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
 
M

manzur

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.
 
J

Jussi Piitulainen

manzur said:
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.

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 >?.
 
R

Roedy Green

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top