in reply to How to use a negative backreference in regex?
This seems to work, using a negative look-ahead.
use strict; use warnings; my @words = qw{ test tesi stoat trout }; my $regex = qr {(?x) ^ (.) .*? (?!\1) . $ }; print m{$regex} ? qq{ Matched: $_\n} : qq{Not matched: $_\n} for @words;
Prints
Not matched: test Matched: tesi Matched: stoat Not matched: trout
I hope this is helpful.
Cheers,
JohnGG
|
|---|