http://www.perlmonks.org?node_id=94582


in reply to Regex probleme, how memorize (match)? with question mark ?

This should match anything after mailto: that isn't a " and ends with "> and put it in $1.
if (/href="mailto:([^"]*)">/) { print "MATCH - ($1)" } else { print "DONT MATCH" }

--
Check out my Perlmonks Related Scripts like framechat, reputer, and xNN.

Replies are listed 'Best First'.
Re: Re: Regex probleme, how memorize (match)? with question mark ?
by tachyon (Chancellor) on Jul 07, 2001 at 00:07 UTC

    Nice regex but you don't need the trailing >. It adds nothing and will cause something that like mailto:foo@bar.com"  > to fail. Either drop it or allow for 0 or more spaces with a \s*

    (/href="mailto:([^"]*)">/     # may fail
    (/href="mailto:([^"]*)"\s*>/  # allows legal spaces
    (/href="mailto:([^"]*)"/      # best option, just match
                                  # what we want
    

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      True. In order to prevent legal whitespace breaking the match there's still some work left undone around the = sign:
      /href\s*=\s*"mailto:([^"]*)"/
      Of course this will still fail by only making a partial match if the email value has a double-quote (unlikely).

      --
      Check out my Perlmonks Related Scripts like framechat, reputer, and xNN.

        And this can still fail because HREF and MAILTO: in caps are valid so we need a /i to make it case insensitive

        /href\s*=\s*"mailto:([^"]*)"/i

        Are we there yet?

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      All right guyz, but you forgot the second statement.
      This regex need to match :

      $_ = '<A class=Title>';

      Your RE match only if there's an "href".

      BobiOne KenoBi ;)