Greediness or non-greediness is only one rule that Perl applies, and it's not the most important rule. The most important rules are (in that order):
- Find a match.
- Of all the possible matches, find one that starts the left most in the query string.
- If a regex can make choices (alternation, repetition) in multiple places (for instance two alternations, two repetitions, or an alternation and a repetition), choices on the left are more significant than choices on the right. That is, it will try all possibilities of the choice on the right before trying the second alternative of the choice on the left.
- In alternation, choices on the left are tried before choices on the right.
- In repetion, greedy choices are preferred over non-greedy once - except when there is a ? modifier, then non-greedy choices are preferred over greedy ones.
Your regex could match in two places: starting from the first slash, and starting from the second (last) slash. Starting at the first slash obeys rule 2. Starting at the second slash obeys rule 5. Rule 2 wins.
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||