Similar to tobyink's solution but doing a global match in case there are multiple "fred"s on your intervals. It seems to work except that it matches twice at each point, probably for similar reasons as explored here.
]$ perl -Mstrict -Mwarnings -E ' $_ = q{abcdefredfghfredijklmnopfredqrs}; for my $n ( 4, 5 ) { say qq{\$n = $n}; say qq{Matched $1 at position @{ [ pos( $_ ) ] }} while m{\G(?:.{$n})*?(?=(fred.*))}g; }' $n = 4 Matched fredijklmnopfredqrs at position 12 Matched fredijklmnopfredqrs at position 12 Matched fredqrs at position 24 Matched fredqrs at position 24 $n = 5 Matched fredfghfredijklmnopfredqrs at position 5 Matched fredfghfredijklmnopfredqrs at position 5 $
I hope this is useful.
Cheers,
JohnGG
In reply to Re: A regex that only matches at offset that are multiples of a given N?
by johngg
in thread A regex that only matches at offset that are multiples of a given N?
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |