The empty pattern //
If the PATTERN evaluates to the empty string, the last successfully matched regular expression is used instead. In this case, only the g and c flags on the empty pattern are honored; the other flags are taken from the original pattern. If no match has previously succeeded, this will (silently) act instead as a genuine empty pattern (which will always match).
That's why your third example works: /a/ matches in both alfa and whatever.
$ printf "Foo\nBar\nQuz\nBaz" | perl -nle 'print // ?"yes":"no"; /a/' yes yes no yes
(See also Repeated Patterns Matching a Zero length Substring, although I think that's less relevant in this case.)
In reply to Re: Empty Regex never fails but failed?
by haukex
in thread Empty Regex never fails but failed?
by leszekdubiel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |