Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: regex extracting text

by JavaFan (Canon)
on Apr 29, 2012 at 10:34 UTC ( [id://967922]=note: print w/replies, xml ) Need Help??


in reply to Re: regex extracting text
in thread regex extracting text

You subtly changed the OPs (.*) into a ([^.]+)? Did you do that on purpose? I believe so, otherwise, the line:
return $str =~ m/\@([^.]+)/ ? $1 : '';
doesn't make sense. The OP original patters allows for the capture of an empty string; and an undefined value will be returned if there was no match. If your pattern is changed to allow empty string matches, you can no longer distinguish between "not a match", and "empty match". You also leave off the matching of a dot, meaning you match on foo@bar, where the OP doesn't. Finally, there's no need to escape the @.

sub name { return $1 if $_[0] =~ /@([^.*])\./; }

Replies are listed 'Best First'.
Re^3: regex extracting text
by sweepy838 (Acolyte) on Apr 29, 2012 at 12:48 UTC
    thanks for that guys.. still learning regex :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2024-04-18 08:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found