pat_mc has asked for the wisdom of the Perl Monks concerning the following question:
#! /usr/bin/perl -w use strict; my $a = "Input String: aaAabBAAa"; my $n = shift @ARGV; $n --; while ( $a =~ /(.)\1{$n}/ig ) { print "$&\n"; pos( $a ) = pos( $a ) - length( $& ) +1; }
I am wondering if there is a more elegant way to do this, e.g. by setting a suitable modifier on the regex. The manual adjustment of the match position after each regex match strikes me as cumbersome.aa aA Aa bB AA Aa
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is there an elegant way of resetting the match position?
by BrowserUk (Patriarch) on Oct 22, 2009 at 18:36 UTC | |
by LanX (Saint) on Oct 22, 2009 at 21:57 UTC | |
|
Re: Is there an elegant way of resetting the match position?
by bv (Friar) on Oct 22, 2009 at 17:04 UTC | |
|
Re: Is there an elegant way of resetting the match position?
by LanX (Saint) on Oct 22, 2009 at 17:46 UTC | |
|
Re: Is there an elegant way of resetting the match position?
by gmargo (Hermit) on Oct 22, 2009 at 18:17 UTC | |
|
Re: Is there an elegant way of resetting the match position?
by GrandFather (Saint) on Oct 22, 2009 at 20:02 UTC | |
|
Re: Is there an elegant way of resetting the match position?
by JadeNB (Chaplain) on Oct 22, 2009 at 21:45 UTC |