I agree that  /(a|b)+/ is better written as  /[ab]+/ in the general case. But  /(a|b)+/ was only intended to exemplify the difference between capturing and non-capturing groups in the split built-in function. Note that a and b in the  (a|b) expression could represent any regex expression, not just the literal characters 'a' and 'b'. That's not true in a character class, which can only be composed of literal characters or another character class, e.g., \s or \w. See perlrecharclass.

... how that "?:" working in the regex.

The  (?symbol(s) ...) syntax was introduced with Perl version 5.10 to support a multitude of regular expression extensions. The  (? sequence was never valid in regexes prior to 5.10, so it was a convenient vehicle for these extensions. So you have
    (?:  non-capturing group)
    (?>  atomic group)
    (?=  positive look-ahead)
    (?<! negative look-behind)
    etc.
See Extended Patterns in perlre. See perlre and perlretut for info on the differences between capturing and non-capturing groups.

See also Special Backtracking Control Verbs for a similar syntactic twist:  (* was never valid pre-5.10.


Give a man a fish:  <%-{-{-{-<


In reply to Re^9: how to remove a string from end of a line by AnomalousMonk
in thread how to remove a string from end of a line by rpinnam

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.