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

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

  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

    On 6 Mar 2006 23:34:32 -0800, "manzur" <> wrote,
    quoted or indirectly quoted someone who said :

    >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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    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. manzur writes:

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

    hiwa Guest

    hiwa, Mar 7, 2006
    #8
  9. manzur

    Roedy Green Guest

    On 6 Mar 2006 23:57:53 -0800, "manzur" <> wrote,
    quoted or indirectly quoted someone who said :

    >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?
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Mar 7, 2006
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kaeli
    Replies:
    8
    Views:
    589
    Chris Smith
    Nov 18, 2004
  2. HS1

    Comparing two strings

    HS1, Nov 28, 2004, in forum: Java
    Replies:
    3
    Views:
    454
    Rob van der Leek
    Nov 29, 2004
  3. Curtis Gilchrist

    Comparing C-Style Strings

    Curtis Gilchrist, Feb 18, 2004, in forum: C++
    Replies:
    5
    Views:
    572
    Default User
    Feb 18, 2004
  4. Rick

    Comparing strings from within strings

    Rick, Oct 21, 2003, in forum: C Programming
    Replies:
    3
    Views:
    375
    Irrwahn Grausewitz
    Oct 21, 2003
  5. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    755
    Malcolm
    Jun 24, 2006
Loading...

Share This Page