Use variable as RegEx pattern

后端 未结 2 1011
礼貌的吻别
礼貌的吻别 2021-02-07 00:23

I\'d like to use a variable as a RegEx pattern for matching filenames:

my $file = \"test~\";
my $regex1 = \'^.+\\Q~\\E$\';
my $regex2 = \'^.+\\\\Q~\\\\E$\';
prin         


        
2条回答
  •  盖世英雄少女心
    2021-02-07 00:51

    You cannot use \Q in a single-quoted / non-interpolated string. It must be seen by the lexer.

    Anyway, tilde isn’t a meta-character.

    Add use regex "debug" and you will see what is actually happening.

提交回复
热议问题