OT: regular expression matching multiple occurrences of one group

sln at netherlands.com sln at netherlands.com
Mon Nov 9 11:55:33 EST 2009


On Mon, 9 Nov 2009 05:53:00 -0800 (PST), 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"?

Is this a ludicrous question, or is it meant for the python group?

use strict;
use warnings;

my @matches = "-c-c-c-c-c" =~ /(-c)/g;
print "\n at matches\n";

@matches = ();
"-c-a-c-c-c" =~ /(?:(-c)(?{push @matches, $^N})|.)+/x;
print "@matches\n";

-sln



More information about the Python-list mailing list