ereg question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • monomaniac21

    ereg question

    hi all

    can anyone tell me, does this condition evaluate to true or false?

    $foo = ereg('ca?t', 'caaaaaaat');

    thanks

    marc

  • Rik

    #2
    Re: ereg question

    monomaniac21 <mcyi2mr3@googl email.comwrote:
    hi all
    >
    can anyone tell me, does this condition evaluate to true or false?
    >
    $foo = ereg('ca?t', 'caaaaaaat');
    False afaik. Forget the POSIX functions, use preg_match();

    To match 'cat' or 'ct':
    preg_match('/ca?t/',$string);

    To match 'cat', 'caat','caaat' etc.
    preg_match('/ca+t/',$string);

    To match 'ct','cat', 'caat','caaat' etc.
    preg_match('/ca*t/',$string);
    --
    Rik Wasmus

    Comment

    • mvandenb@gmail.com

      #3
      Re: ereg question

      Regex reference:

      It basic but it works.


      'ca?t' translated in to English:

      find the string 'ct' or 'cat'

      ? - match 1 or 0 occurrences

      + - match 1 or more occurrences 'cat' 'ca...at'

      * - match 0 or more occurrences 'ct' 'cat' 'ca...at'

      There is more but see the link above.

      Comment

      • kenleycapps@gmail.com

        #4
        Re: ereg question

        If you're looking to interactively test regex, why not use something
        like Regex Coach? http://weitz.de/regex-coach/

        Very good tool. I can't live without it. Windows only though, as far
        as I know.

        On Jan 26, 2:01 pm, mvand...@gmail. com wrote:
        Regex reference:http://en.wikipedia.org/wiki/Regular_expression
        It basic but it works.
        >
        'ca?t' translated in to English:
        >
        find the string 'ct' or 'cat'
        >
        ? - match 1 or 0 occurrences
        >
        + - match 1 or more occurrences 'cat' 'ca...at'
        >
        * - match 0 or more occurrences 'ct' 'cat' 'ca...at'
        >
        There is more but see the link above.

        Comment

        Working...