On Thu, Dec 20, 2012 at 11:39 PM, Feng He <[email protected]> wrote:
> 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.
>
A couple of like problems:
You probably had $string double quoted instead of
single quoted which later results in the \ being eaten.
Example: $string = "dns\.support.dnsbed.com";
After perl parsing, the $string is now "dns.support.dnsbed.com"
and your regex produces the output you saw.
If, instead $string = "dns\\support.dsnbed.com", then your regex
output would be: dns\[email protected]
That's closer to what you want... one solution to the unwanted \
would be $user =~ tr/\\//d;
--
Charles DeRykus
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/