Alternation is constrained only by grouping parens, or by the pattern as a whole. In your case, you've got two alternates of choice:

(.*)EDITION/

...or...

Edition/

Whichever of those alternates matches will be captured into $1. $2 will only be populated if the first alternate is matched, however. $3 will always be populated with something (assuming the overall pattern match is successful), even if that something is an empty string; it takes place outside of the alternation.

The \/ construct equates to the literal forward slash. It has to be escaped with a backslash so that it doesn't get confused with the m// operator's terminating /.

As for your last question: $1 will get everything matched by (.*)EDITION\/|Edition\/. $2 will get everything matched by the first (.*), but only if the first alternate in your alternation is matched. $3 will get everything matched by the final (.*).

What are you actually wanting to match? Is it true that you only want $2 to be populated with a useful value if the text contains EDITION/, but not if it contains Edition/?


Dave


In reply to Re: Understand Regex syntax by davido
in thread Understand Regex syntax by manishrathi

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.