comparing strings

Discussion in 'Java' started by manzur, Mar 7, 2006.

  1. manzur

    manzur Guest

    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
     
    manzur, Mar 7, 2006
    #1
    1. Advertisements

  2. manzur

    Bart Cremers Guest

    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
     
    Bart Cremers, Mar 7, 2006
    #2
    1. Advertisements

  3. manzur

    hiwa Guest

    if (myString.matches("^\\d:\\d:\\d$")){
    ...
    }
     
    hiwa, Mar 7, 2006
    #3
  4. manzur

    manzur Guest

    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
     
    manzur, Mar 7, 2006
    #4
  5. manzur

    Roedy Green Guest

    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.
     
    Roedy Green, Mar 7, 2006
    #5
  6. manzur

    manzur Guest

    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.
     
    manzur, Mar 7, 2006
    #6
  7. 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 >?.
     
    Jussi Piitulainen, Mar 7, 2006
    #7
  8. manzur

    hiwa Guest

    hiwa, Mar 7, 2006
    #8
  9. manzur

    Roedy Green Guest

    Did you read the link I gave you?
    Did you do write an experimenting regex class?
     
    Roedy Green, Mar 7, 2006
    #9
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.