in reply to Re^2: Style question: regex versus string builtin function
in thread Style question: regex versus string builtin function

A \Q does not "fill" an empty regex.

use Test::More 'tests' => 5; ok( 'foo' =~ //, 'empty regex matches' ); ok( 'foo' =~ /foo/, '/foo/ matches' ); ok( !('bar' =~ //), 'repeated match of foo' ); ok( !('bar' =~ /\Q/), 'repeated match with \\Q' ); my $empty = ''; ok( !('bar' =~ /\Q$empty/), 'interpolated empty string same as \\Q' );

Replies are listed 'Best First'.
Re^4: Style question: regex versus string builtin function
by throop (Chaplain) on Oct 02, 2007 at 15:24 UTC
    Well, dang!

    I'd recommended using index because of (inter alia) some gnarly behavior with empty patterns. But it turns out it was even more gnarly than I thought.

    BTW, perlreref says

    If 'pattern' is an empty string, the last I matched regex is used.
    What is the 'I' in 'I matched'? I couldn't find it mentioned again in perlre or perlreref, and searching on 'I' turned out to be ... overproductive.

    throop

      A bug in perlreref? On my screen, I see:

      If ’pattern’ is an empty string, the last I<successfully> matched

      I know too little about POD to say whether this is a problem with the web rendering or a problem with how the file is written.