in reply to Re^2: Quick Regex Question
in thread Quick Regex Question
OK, change the regex to:
/INC\d{7}(?:[^\d]|$)/
which should match only exactly 7 digits. (INC followed by 7 digits followed by either a non-digit or the end of the string.)
Update: Better solutions:
/INC\d{7}(?!\d)/
using a zero-width negative look-ahead assertion; or:
/INC\d{7}(?:(?=\D)|$)/ # Corrected: See post by AnomalousMonk, belo +w.
using a zero-width positive look-ahead assertion together with \D as per GrandFather’s suggestion. See Extended Patterns.
Athanasius <°(((>< contra mundum
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Quick Regex Question
by GrandFather (Saint) on Oct 08, 2012 at 23:29 UTC | |
Re^4: Quick Regex Question
by AnomalousMonk (Archbishop) on Oct 09, 2012 at 12:36 UTC |
In Section
Seekers of Perl Wisdom