G'day Rolf,

Purely for readability, I generally try to keep the modifiers in alphabetical order. In that respect, I concur with ++hippo's response.

I'm pretty sure that the "xms default" came about, because that was the order they were introduced in the book "Perl Best Practices".

  1. Always use the /x flag. (pp. 236-237)
  2. Always use the /m flag. (pp. 237-239)
  3. Always use the /s flag. (pp. 240-241)

Some modifiers can be applied to the regex itself (e.g. /x); others, to any operation the regex is involved in (e.g. /g); and others to only a specific operation (e.g. /e). It's a fatal error to use them in the wrong places:

$ perl -E 'say qr{}x' (?^ux:) $ perl -E 'say qr{}g' Unknown regexp modifier "/g" at -e line 1, near "say " Execution of -e aborted due to compilation errors. $ perl -E 'say m{}g' $ perl -E 'say m{}e' Unknown regexp modifier "/e" at -e line 1, near "say " Execution of -e aborted due to compilation errors. $ perl -E 'say s{}{}e' 1

I can see some benefit in keeping those grouped together: your initial example of xegis would become isxge.

I'm also not averse to ++AnomalousMonk's suggestion of using a separator. In which case, xegis would become isx_g_e.

Overall, I'm not too bothered by personal preferences regarding modifier ordering: deciding upon a single style, and using it consistently, is far more important, in my opinion.

— Ken


In reply to Re: Best Practice: Order of regex modifiers? by kcott
in thread Best Practice: Order of regex modifiers? by LanX

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.