Greetings,

Here is one way of doing it. I admit there will be better solutions to this.

while (<DATA>) {
    if(/
        (\w+) #Match dns
        \.       #Match dot
        (\w+) #Match support
        (@)   #Match @
        (\w+) #Match dnsbed
        \.       #Match dot
        (\w+) #Match com
        /x) {
    print "$1.$2$3$4.$5";
    }
}

__DATA__
[email protected]
 
best,
Shaji 
-------------------------------------------------------------------------------
Your talent is God's gift to you. What you do with it is your gift back to God.
-------------------------------------------------------------------------------


________________________________
 From: Guoke Zhou (Wicresoft) <[email protected]>
To: Feng He <[email protected]> 
Cc: "[email protected]" <[email protected]> 
Sent: Friday, 21 December 2012 2:01 PM
Subject: RE: Help with a regex
 

$string='dns\.support.dnsbed.com';  
print "$string\n";
if ($string =~ /^(.*?)\\\.(.*?)(?<!\\)\.(.*)$/) {
        print $1.".".$2."@".$3;
     }

Output:
dns\.support.dnsbed.com
[email protected]

我猜你遇到的是转义的问题。。。

-----Original Message-----
From: Feng He [mailto:[email protected]] 
Sent: Friday, December 21, 2012 3:39 PM
To: [email protected]
Subject: Help with a regex

Hello,

I have a string like: dns\.support.dnsbed.com I want to translate it to a 
regular email address: [email protected]


    if ($string =~ /^(.*?)(?<!\\)\.(.*)$/) {
        my $user = $1;
        my $tld = $2;
        return $user . '@'. $tld;
     }

But this won't work correctly. I got:
[email protected]

Where do I get wrong? Thanks.

--
To unsubscribe, e-mail: [email protected] For additional commands, 
e-mail: [email protected] http://learn.perl.org/ 

Reply via email to