I ended up with ([^\-]). ... difference?
It depends on exactly what you want. ([^\-]) requires a character match and consumes a character. As LanX pointed out, ([^\-]|$) consumes a character if it can. Neither seem to do what you want:
Maybe this does:c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'test atest atested tested test- -test test .test test. test' +; ;; $s =~ s/\b(test)([^-])/DONE/g; print qq{'$s'}; " 'DONEatest atested DONEd test- -DONEDONE.DONEDONE test' c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'test atest atested tested test- -test test .test test. test' +; ;; $s =~ s/\b(test)([^-]|$)/DONE/g; print qq{'$s'}; " 'DONEatest atested DONEd test- -DONEDONE.DONEDONE DONE'
c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'test atest atested tested test- -test test .test test. test' +; ;; $s =~ s/\b(test)(?!-)\b/DONE/g; print qq{'$s'}; " 'DONE atest atested tested test- -DONE DONE .DONE DONE. DONE'
Update: Just noticed from the timestamps that ultranerds already decided to go with LanX's suggestion. :)
Give a man a fish: <%-{-{-{-<
In reply to Re^3: Regex boundary match (updated demo code)
by AnomalousMonk
in thread Regex boundary match
by ultranerds
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |