Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re: Regex probleme, how memorize (match)? with question mark ?

by tachyon (Chancellor)
on Jul 07, 2001 at 00:07 UTC ( [id://94587]=note: print w/replies, xml ) Need Help??


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

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

  • Comment on Re: Re: Regex probleme, how memorize (match)? with question mark ?

Replies are listed 'Best First'.
Re: Re: Re: Regex probleme, how memorize (match)? with question mark ?
by epoptai (Curate) on Jul 07, 2001 at 00:21 UTC
    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

        I can see two improvements toward making it bulletproof:

        1. you never know when someone will use single quotes
        2. or linebreaks

        In this kind of golf the code tends to get longer 8^}

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

        Someone should mention HTML::Parser.

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

Re: Re: Re: Regex probleme, how memorize (match)? with question mark ?
by bobione (Pilgrim) on Jul 07, 2001 at 02:07 UTC
    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 ;)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://94587]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-24 12:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found