perl6 否定用户定义的字符 class

perl6 negating user-defined caracter class

我试图忽略所有带有引号的行,不知何故有点混淆:

> my $y='\"\""';
\"\""
> so $y ~~ m/<-[\"]>/
True                      # $y has a " mark, so I want it to be False
> $y ~~ m/<-[\"]>/
「\」
>  $y ~~ m:g/<-[\"]>/
(「\」 「\」)
> $y ~~ m:g/<-["]>/
(「\」 「\」)
$y ~~ m/<-[\]>/
「"」
> $y ~~ m/<-[\\"]>/
False

<-[\"]> 与 <-["]> 相同吗?

> say '"in quotes"' ~~ / '"' <-[ " ]> * '"'/;
「"in quotes"」
> say 'no "foo" quotes' ~~ /  <-[ " ]> + /;
「no 」
> say 'no "foo" quotes' ~~ /  <-[ \" ]> + /;
「no 」

在 perl6 文档示例中,https://docs.perl6.org/language/regexes#Wildcards_and_character_classes,作者不必转义引号;但是,我必须逃避它才能工作, <-[\\"]> ,即转义 \ 和转义 "。我误会了什么?

谢谢!!

您不需要在字符 class 规范中转义字符,反斜杠本身除外:因此指定 <-[\"]> 相同=12=]。并指定 <-[\"]>,表示所有字符 除了 \".

但是,您可能有更简单的方法:如果您只想查找字符串中的单个(一组)字符,则 contains:

my $y = "foo bar baz";
say $y.contains("oo");    # True

这通过使用一个简单的低级字符串匹配来绕过所有昂贵的正则表达式/语法机制。