almaric has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
just a quick question. Short scan over a few regexp tutorials didn't lead me to an answer.
outputs:$a="aaaa"; @a=$a=~m/aa/g; print join ( "-", @a );
But with another pov one could find 3 occurences of 'aa' in 'aaaa' but I think this is a question of how matching is defined in perl.aa-aa
Is there a way to manipulate the regexp above to match 3 times in the given string or do I have to write my own sub for this task?
Any suggestion to do this the "perl way"?
Thanks!
PS: A friend came up with the following, non-experimental :) suggestion
Greetings$regexp="a{2}"; $a="aaaa"; @a=$a=~m/(?=($regexp))./g; print join ( "-", @a );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: multiple matches with regexp
by thelenm (Vicar) on Oct 10, 2003 at 21:20 UTC | |
Re: multiple matches with regexp
by Aristotle (Chancellor) on Oct 10, 2003 at 17:42 UTC | |
Re: multiple matches with regexp
by CombatSquirrel (Hermit) on Oct 10, 2003 at 20:23 UTC | |
by sandfly (Beadle) on Oct 10, 2003 at 21:08 UTC | |
by CombatSquirrel (Hermit) on Oct 10, 2003 at 22:04 UTC | |
by almaric (Acolyte) on Oct 11, 2003 at 17:25 UTC | |
by almaric (Acolyte) on Oct 11, 2003 at 00:46 UTC | |
Re: multiple matches with regexp
by davido (Cardinal) on Oct 10, 2003 at 20:00 UTC | |
by almaric (Acolyte) on Oct 11, 2003 at 00:51 UTC |
Back to
Seekers of Perl Wisdom