in reply to Re^3: Question on Regular Expression
in thread Question on Regular Expression
Can you please let me know how to make use of %+ so to match in a loop even if the submatch in a pattern string fails?
um, \d always fails :)
#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; my $cool = qr/ (?<key> \s* (?<key2>\w+) \s* (?<keyQ>\w+) \s* (?<NEVER>\d*) ) /x; my $beans = 'castor cocoa coffee pinto navy Mayocoba'; while( $beans =~ m{$cool}g ){ dd( \%+ ); } __END__ { # tied Tie::Hash::NamedCapture key => "castor cocoa ", key2 => "castor", keyQ => "cocoa", NEVER => "", } { # tied Tie::Hash::NamedCapture key => "coffee pinto ", key2 => "coffee", keyQ => "pinto", NEVER => "", } { # tied Tie::Hash::NamedCapture key => "navy Mayocoba", key2 => "navy", keyQ => "Mayocoba", NEVER => "", }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Question on Regular Expression
by sjain (Initiate) on Dec 28, 2014 at 13:32 UTC | |
by choroba (Cardinal) on Dec 28, 2014 at 14:44 UTC | |
by Anonymous Monk on Dec 28, 2014 at 20:33 UTC |