Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Answer: How can I use backrefs in a lookbehind?

by Ieronim (Friar)
on Jun 28, 2006 at 21:51 UTC ( #558162=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > How can I use backrefs in a lookbehind? - Answer 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

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[Tanktalus]: choroba: you need to auto-pull last hour of cb when you start up so the user gets some level of context. snicker :)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2017-09-19 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (230 votes). Check out past polls.

    Notices?