in reply to Regex pattern that fails when string contains a certain pattern
Hm. You've described what you don't want to match rather than what you do want to match, and what you've described doesn't correspond to the examples you've given.
Why should the last example not match given it doesn't contain a separator at all?
Updated with addition rule:
#! perl -slw use strict; my @good = qw[ aa1.2 aa1_bb2 ]; my @bad = qw[ aa1_2 aa1_2bb 1aa ]; my $re = qr[^[0-9]|^.*[_-][0-9]]; print $_, $_ !~ $re ? ' matches.' : ' doesnt match' for @good, @bad; __END__ C:\test>junk aa1.2 matches. aa1_bb2 matches. aa1_2 doesnt match aa1_2bb doesnt match 1aa doesnt match
|
|---|