in reply to match sequences of words based on number of characters
Another way:
>perl -wMstrict -le "my $s = 'aaaa bb ccccc ddd eeeeeee ffff gg hhhhh iii jjjjjjj'; ;; for my $ar ([2, 5, 3], [3, 7, 4], [4, 2],) { my $rx = rxg(@$ar); print $rx; my @groups = $s =~ m{ ($rx) }xmsg; print qq{'$_' } for @groups; } ;; sub rxg { my ($rx) = map qr{ \b $_ \b }xms, join ' \s+ ', map qq{\\w{$_}}, @_ ; ;; return $rx; } " (?^msx: \b \w{2} \s+ \w{5} \s+ \w{3} \b ) 'bb ccccc ddd' 'gg hhhhh iii' (?^msx: \b \w{3} \s+ \w{7} \s+ \w{4} \b ) 'ddd eeeeeee ffff' (?^msx: \b \w{4} \s+ \w{2} \b ) 'aaaa bb' 'ffff gg'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: match sequences of words based on number of characters
by nicemank (Novice) on Feb 17, 2013 at 21:17 UTC | |
by AnomalousMonk (Archbishop) on Feb 17, 2013 at 21:47 UTC | |
Re^2: match sequences of words based on number of characters
by frozenwithjoy (Priest) on Feb 17, 2013 at 23:56 UTC | |
by AnomalousMonk (Archbishop) on Feb 18, 2013 at 03:25 UTC | |
by frozenwithjoy (Priest) on Feb 18, 2013 at 04:00 UTC |
In Section
Seekers of Perl Wisdom