Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Regex being stupid

by Athanasius (Archbishop)
on Sep 19, 2013 at 03:10 UTC ( [id://1054764]=note: print w/replies, xml ) Need Help??


in reply to Regex being stupid

The code fragment shown has a number of problems. First, the string used to initialise $text contains the “@” symbol, which triggers interpolation within double quotes. This needs to be escaped, or else change to single quotes.

Second, the replacement part of a substitution cannot contain assertions such as \w+. Third, as davido says, the regex will fail to match because it requires a whitespace character (\s) before the first capture, but the given string does not contain any whitespace in that position.

Try this as a start:

#! perl use strict; use warnings; my $text = 'pilar@delphoss.com type add (#090930-230011-907000 ur22122 +021 pi'; $text =~ /(\w+)@(\w+)\.com/; print "$1\@$2\n";

Output:

12:59 >perl 724_SoPW.pl pilar@delphoss 13:06 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Regex being stupid
by AI Cowboy (Beadle) on Sep 19, 2013 at 03:20 UTC
    Looks good, and I didn't know you can't use \w in the replacement part of s/. Also, the code fragment may have errors inside the quotes itself (I updated it however - thanks for pointing that out), but the quotes and the way the variable is set is not what actually happens in my code, it was just an attempt at speeding the question along to ask, basically, "you have a weird variable, grab email address nao".

    Many thanks for your help, I will give it a try :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found