in reply to Re: Make a variable safe for a regex.
in thread Make a variable safe for a regex.

Is there a way to do this for UTF-8 strings too? \Q will break multi-byte characters.
  • Comment on Re^2: Make a variable safe for a regex.

Replies are listed 'Best First'.
Re^3: Make a variable safe for a regex.
by Corion (Patriarch) on Mar 03, 2007 at 18:53 UTC

    Can you supply a test case for that? I've tried (shortly) and it seems to work for me:

    C:\>perl -le "my $str = qq(foo\x{100}bar); my $re = qr/^\Q$str\E/; war +n $str; warn $re; warn $str =~ /$re/;" foo─Çbar at -e line 1. (?-xism:^foo─Çbar) at -e line 1. 1 at -e line 1.

    Maybe it fails for some other cases of unicode chars, and if so I'd consider that a bug.