Perl6 negating user defined caracter class

I'm trying to ignore all the lines that have quotes in it, somehow it looks like:

> 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

      

Is <- [\ "]> the same as <- ["]>?

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

      

In the perl6 documentation example https://docs.perl6.org/language/regexes#Wildcards_and_character_classes, the author didn't need to hide the quote; however, I need to escape for it to work, <- [\\ "]>, that is, escape \ and escape". What have I misunderstood?

Thank!

+3


source to share


1 answer


You don't need to escape characters inside a character class specification other than the backslash itself: so the specification is the <-[\"]>

same as <-["]>

. And the indication <-[\\"]>

indicates all characters except \

and "

.

However, there might be an easier way for you: if you are looking for only one (set) of character (s) per string, there contains

:



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

      

This bypasses all expensive regex / grammar machines using one simple low level string match.

+6


source







All Articles