Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^3: matching problem

by AnomalousMonk (Chancellor)
on Feb 26, 2013 at 20:49 UTC ( #1020753=note: print w/replies, xml ) Need Help??

in reply to Re^2: matching problem
in thread matching problem

... 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020753]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2018-09-22 09:43 GMT
Find Nodes?
    Voting Booth?
    Eventually, "covfefe" will come to mean:

    Results (190 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!