my $formget = qr(10-[KQ][A-Z0-9]*(?!/))i;

The problem with this regex when used in a  /^$formget/ match is that it allows strings like  10-KA/ to match: if a  / is found at the end of  10-KA/ the regex can backtrack to  10-K and look ahead to  A which is not a  / character! BrowserUk's approach below gets around this by using an end-of-string anchor assertion to make sure that only non-/ characters follow the [KQ]. If anchoring were not possible, another way would be to use an 'atomic'  (?>pattern) group which will not allow backtracking into it:

c:\@Work\Perl\monks>perl -wMstrict -le "my @tests = qw[ 10-K 10-KSB 10-K405 10-KSB405 10-Q 10-K/B 10-KSB/ABC 10-K405/A 10-KSB405/A 10-Q/A 10-KA/ ]; ;; my $formget = qr{ (?i) 10- [KQ] [A-Z0-9]* (?! /) }xms; printf 'valid: '; /^$formget/ and printf qq{'$_' } for @tests; print ''; ;; my $formget2 = qr{ (?> (?i) 10- [KQ] [A-Z0-9]*) (?! /) }xms; printf 'valid2: '; /^$formget2/ and printf qq{'$_' } for @tests; " valid: '10-K' '10-KSB' '10-K405' '10-KSB405' '10-Q' '10-KSB/ABC' '10- +K405/A' '10-KSB405/A' '10-KA/' valid2: '10-K' '10-KSB' '10-K405' '10-KSB405' '10-Q'


In reply to Re^2: Pattern matching exlusion by AnomalousMonk
in thread Pattern matching exlusion by wrkrbeee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.