Hi Punit,

see below for my reply.

On Thu, 9 Jun 2016 14:17:17 +0530
Punit Jain <contactpunitj...@gmail.com> wrote:

> Hi ,
> 
> Below is the problem I am facing :
> 
> #!/usr/bin/perl
> 

Always start your program with "use strict;" and "use warnings;" or equivalent.
See:

* http://perl-begin.org/tutorials/bad-elements/

> my @str = ('mailto:y...@gmail.com','ldap:///uid=user1,ou=People,o=test.com
> ');
> 
> foreach (@str) {
> 

Please use an explicit literal variable in foreach, see:

http://perl-begin.org/tutorials/bad-elements/#overuse_dollar_underscore

>         # split off ldaps and mailtos
> 
>         my @addr = $_ =~
> 
>           /ldap:\/\/\/(.+)|mailto:(.+)/;
> 
>          print $1;

The problem here is that the two (.+) are different captures - $1 and $2. What
you can try doing is either:

m#(?:ldap:///|mailto:)(.+)#

or alternatively use named captures: http://www.perlmonks.org/?node_id=680796 .

also note that you should always check that the regular expression matches and
preferably extract its matches from the return list.

Regards,
        Shlomi Fish
 
> 
> }
> 
> 
> When i run this I get  uid=user1,ou=People,o=test.com as output however
> don't get y...@gmail.com printed.
> 
> Can anyone point me to single regex to achieve this ? I know how to handle
> it with different regex checks but need a single regex.
> 
> 
> Regards,
> 
> Punit



-- 
-----------------------------------------------------------------
Shlomi Fish

Chuck Norris is not afraid of superstitions. Superstitions are afraid of Chuck
Norris. (via Dov Levenglick)

Please reply to list if it's a mailing list post

-- 
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