In general, I agree with the points in your reply, but a coupla quibbles...

... the modifiers xms ... would be better as:
/atg (.+?) (?>taa|tag|tga)/msx
[emphasis added]

Why better? The modifiers are given in alphabetic order in a  Regexp object stringization, but what is the advantage of keeping that order? I thought TheDamian used the  //xms ordering throughout PBP simply because it happened to be the order in which those modifiers were introduced and discussed in the regex section of the book, not because of any inherent advantage. Is their order not irrelevant to compilation/execution?

Also, what is the advantage of using atomic grouping for the  (?>taa|tag|tga) stop codon (if that's the right terminology) sub-pattern? My understanding is that the primary (maybe the only?) purpose of atomic grouping is to defeat backtracking in situations in which the programmer knows backtracking will impair performance. In the example regex, once the stop codon pattern matches, the overall match succeeds; there is never any backtracking to defeat. (This is already discussed in part here, but I still don't see any advantage.)

... in your real code, unless you're ensuring that $dna is always lowercase (e.g. by using lc), you should also add the i modifier ...

I would emphasize that it's usually very important to ensure lower- (or canonical-) casing for long string matches because the  //i modifier can impose a significant performance hit. In the benchmarks I did here, just adding  //i to my equivalent of the
    /atg(.+?)(?:taa|tag|tga)/
regex incurred a 30% - 35% hit.


In reply to Re^2: Simple regex question. Grouping with a negative lookahead assertion. by AnomalousMonk
in thread Simple regex question. Grouping with a negative lookahead assertion. by Anonymous Monk

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.