Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Answer: How can I use backrefs in a lookbehind?

( #558162=categorized answer: print w/ replies, xml ) Need Help??

Q&A > regular expressions > How can I use backrefs in a lookbehind? contributed by Ieronim

Only a small remark:
The idea of variable-length lookbehind is very good, but the given problem can be solved even without using lookbehinds at all:
#!/usr/bin/perl use warnings; use strict; my $pat = qr{ ( # 1: capture the whole substring (?: (.) # a character (?!\2\2) # NOT repeated three times ){1,4} # one to four of such 'good' characters .. # two any characters more; 2+4 = 6 ) }x; foreach (qw/AABBCCDD AABBBCCD AAABBCCD AABBCCCD AAABCDE/) { print "$1\n" if /$pat/; }
outputs
AABBCC AABB AABBCC AABBCC AABCDE

Comment on Answer: How can I use backrefs in a lookbehind?
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2014-11-01 04:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (227 votes), past polls