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

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: Regex pattern that fails when string contains a certain pattern
  • Download Code