Sewi has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
a really simple RegEx problem is driving me crazy trying to find the most-often recurring char combination:
Why doesn't {2,} match ab?
Thanks, Sewi
a really simple RegEx problem is driving me crazy trying to find the most-often recurring char combination:
Simple, but I need to match only strings with a minimum of 2 chars:perl -le 'print $x = "abcdefgxxabcdefgzzabcdsjfhkdfab"; print $2 if $x + =~ /((\w+).*?\2.*?)+/;' abcdefgxxabcdefgzzabcdsjfhkdfab ab
Shows abcdefg but ab would be right (there is another abc behind the zz and another ab at the end).perl -le 'print $x = "abcdefgxxabcdefgzzabcdsjfhkdfab"; print $2 if $x + =~ /((\w{2,}).*?\2.*?)+/;' abcdefgxxabcdefgzzabcdsjfhkdfab abcdefg
doesn't work either, as ab would be right.perl -le 'print $x = "abcdefgxxabcdefgzzabcdsjfhkdfab"; print $2 if $x + =~ /((\w{2,}?).*?\2.*?)+/;' abcdefgxxabcdefgzzabcdsjfhkdfab cd
Why doesn't {2,} match ab?
Thanks, Sewi
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: RegEx + vs. {1,}
by grizzley (Chaplain) on Oct 10, 2012 at 12:01 UTC | |
by Sewi (Friar) on Oct 10, 2012 at 13:01 UTC | |
by grizzley (Chaplain) on Oct 10, 2012 at 15:11 UTC | |
Re: RegEx + vs. {1,}
by trizen (Hermit) on Oct 10, 2012 at 12:25 UTC | |
by Athanasius (Archbishop) on Oct 10, 2012 at 16:03 UTC | |
Re: RegEx + vs. {1,}
by MidLifeXis (Monsignor) on Oct 10, 2012 at 12:32 UTC | |
Re: RegEx + vs. {1,}
by Anique (Acolyte) on Oct 10, 2012 at 12:26 UTC | |
Re: RegEx + vs. {1,}
by ELISHEVA (Prior) on Oct 10, 2012 at 14:16 UTC | |
by choroba (Cardinal) on Oct 10, 2012 at 14:25 UTC | |
by tobyink (Canon) on Oct 10, 2012 at 22:08 UTC | |
by grizzley (Chaplain) on Oct 11, 2012 at 07:32 UTC |
Back to
Seekers of Perl Wisdom