Re: match pattern
> "JB" == Jim Bauer writes: >> if ( m!(www.\S+.com)!s ) { JB> Try m!(www.\S+.com)!sg don't use alternate delimiters unless you must. it makes for harder to read code. stick with // unless you have a / inside the regex. and the best alternate delimiters are paired ones like {} as they are the most readable. and when you use // you don't need the m operator. this is for the OP and this replier who used ! as the delimiter. uri -- Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- - Perl Code Review , Architecture, Development, Training, Support -- - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com - -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: match pattern
"raphael()" wrote on Fri, 18 Sep 2009 22:10:01 +0530: >Hi > >How do I pick out matching words if there are more than one on the same >line? > > >Example > >INFILE.TXT > >www.site01.com www.site02.com www.site03.com >www.site04.com > >-- > >while (<>) { >if ( m!(www.\S+.com)!s ) { Try m!(www.\S+.com)!sg (See "Regexp Quote-Like Operators" in Perlop.) -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: match pattern
raphael() wrote: Hi How do I pick out matching words if there are more than one on the same line? Example INFILE.TXT www.site01.com www.site02.com www.site03.com www.site04.com -- while (<>) { if ( m!(www.\S+.com)!s ) { # print "$1\n"; # print "$&\n"; print; }; } -- I want to get all the 'match' in the INFILE.TXT on separate lines to OUTFILE.TXT www.site01.com www.site02.com www.site03.com www.site04.com But all I get is www.site01.com www.site04.com If I try $1 or $& I only get two instances of 'match' from the first in the line. Any help is appreciated You use the /g flag to get more than one match in a loop: #!/usr/bin/perl use strict; use warnings; while( ){ while( m{ \b ( www \. \S+ \. com ) \b }gmsx ){ print "$1\n"; } } __DATA__ www.site01.com www.site02.com www.site03.com www.site04.com -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
match pattern
Hi How do I pick out matching words if there are more than one on the same line? Example INFILE.TXT www.site01.com www.site02.com www.site03.com www.site04.com -- while (<>) { if ( m!(www.\S+.com)!s ) { # print "$1\n"; # print "$&\n"; print; }; } -- I want to get all the 'match' in the INFILE.TXT on separate lines to OUTFILE.TXT www.site01.com www.site02.com www.site03.com www.site04.com But all I get is www.site01.com www.site04.com If I try $1 or $& I only get two instances of 'match' from the first in the line. Any help is appreciated