Help for this page

Select Code to Download


  1. or download this
    my $haystack = 'lets test[1] this thing $string';
    my @tests = ('test[1]', '\Etest[1]\Q', 'test\[1\]');
    @tests = map {$_, qr"\Q$_\E"} @tests;
    
    print "Check $_:" . ($haystack =~ /($_)/ ? "got $1\n" : "no match\n") 
    +for @tests;
    
  2. or download this
    Check test[1]:no match
    Check (?^:test\[1\]):got test[1]
    Check \Etest[1]\Q:no match
    Check (?^:\\Etest\[1\]\\Q):no match
    Check test\[1\]:got test[1]
    Check (?^:test\\\[1\\\]):no match