OT: regular expression matching multiple occurrences of one group
Jürgen Exner
jurgenex at hotmail.com
Mon Nov 9 12:18:54 EST 2009
pinkisntwell <pinkisntwell at gmail.com> wrote:
>How can I make a regular expression that will match every occurrence
>of a group and return each occurrence as a group match? For example,
>for a string "-c-c-c-c-c", how can I make a regex which will return a
>group match for each occurrence of "-c"?
Where is the problem? The most straight-forward, simplest approach works
just fine:
use strict; use warnings;
my $s = '-c-c-c-c-c';
my @matched = $s=~/-c/g;
print "Found ". @matched . " occurences of '-c':\n";
print join "\n", @matched;
Or did you forget to use the g modifier?
jue
More information about the Python-list
mailing list