in reply to regex to match double letters but not triple or more
Depending on what you are doing, you might find it cleaner to extract all same-letter sequences, then filtering out those of the incorrect length.
if ( grep length( $_ ) == 2, /([A-Za-z]\1+)/g ) { say "match"; } else { say "no match"; }
Otherwise, you could use (*SKIP).
/([A-Za-z])\1(?:\1+(*SKIP)(*FAIL))?/
For example:
perl -e' use v5.14; for ( "aa", "bbb", "cccc", "deefffgggghhiiiii" ) { say s/([A-Za-z])\1(?:\1+(*SKIP)(*FAIL))?/[$&]/gr; } '
[aa] bbb cccc d[ee]fffgggg[hh]iiiii
|
|---|