Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
... excellent exposition!

Thank you very much!

... the empty regex acts as a stand-in for the regex most recently matched (whether the match was successful or not).

In looking for empty pattern documentation (see below), I discovered this is not the case: "If the PATTERN evaluates to the empty string, the last successfully matched regular expression is used instead." (Strange what you can find when you actually read the docs!) Fixed my reply: thanks!

Is this documented anywhere?

The only place I've seen it is in perlop in the Regexp Quote-Like Operators section: the discussion of the  m// operator has a sub-section titled "The empty pattern //" (there's also a brief back-reference to it in the discussion of the  s/// operator).

Are there any typical use cases for employing the empty regex to mean “repeat the regex used in the previous match”?

My vague impression is this is something that evolved early-on as an emulation of shell usage or maybe from a desire for some kind of command line one-liner short-cut facility: saves typing, y'know. Offhand, I can't come up with a compelling example.

In reply to Re^3: matching problem by AnomalousMonk
in thread matching problem by Balaton

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    and not a whimper to be heard...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (5)
    As of 2018-06-25 11:47 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.