Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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

by bobione (Pilgrim)
on Jul 06, 2001 at 23:42 UTC ( #94577=perlquestion: print w/replies, xml ) Need Help??

bobione has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, Kings of Regular Expression.
I have got an horrible RE problem (for me :)

I'd like to match a variable witch could be both value of $_ and return a value of the mail or an empty value.

$_ = '<A class=Member href="">'; $_ = '<A class=Title>'; if (/^.*(?:mailto:)([^>]*)?"?>.*$/) {print "MATCH - ($1)";} else {print "DONT MATCH";}

This doesn't match "Mail-Less" case, and prefere keep the last double-quote (") because there's a (?).

I know it's a real small question, but that make me crazy !!
Thanks for your help.

BobiOne KenoBi ;)

Replies are listed 'Best First'.
Re: Regex probleme, how memorize (match)? with question mark ?
by epoptai (Curate) on Jul 06, 2001 at 23:52 UTC

      Nice regex but you don't need the trailing >. It adds nothing and will cause something that like"  > 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




        True. In order to prevent legal whitespace breaking the match there's still some work left undone around the = sign:
        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.

        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 ;)

Re: Regex probleme, how memorize (match)? with question mark ?
by I0 (Priest) on Jul 08, 2001 at 10:37 UTC
    What do you want to happen in the "Mail-Less" case?
Re: Regex probleme, how memorize (match)? with question mark ?
by Anonymous Monk on Mar 10, 2017 at 16:15 UTC
    (?: ) means, do not memorize!!!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://94577]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2019-11-16 00:01 GMT
Find Nodes?
    Voting Booth?
    Strict and warnings: which comes first?

    Results (85 votes). Check out past polls.