On Thu, Dec 20, 2012 at 11:39 PM, Feng He <fen...@nsbeta.info> wrote:
> Hello,
>
> I have a string like: dns\.support.dnsbed.com
> I want to translate it to a regular email address: dns.supp...@dnsbed.com
>
>
>     if ($string =~ /^(.*?)(?<!\\)\.(.*)$/) {
>         my $user = $1;
>         my $tld = $2;
>         return $user . '@'. $tld;
>      }
>
> But this won't work correctly. I got:
> d...@support.dnsbed.com
>
> 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\.supp...@dnsbed.com

That's closer to what you want... one solution to the unwanted \
would be $user =~ tr/\\//d;

-- 
Charles DeRykus

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to