I am trying to ignore all lines that has a quotation mark in it, somehow it is kind of onfusing:
> 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 perl6 documentation example, https://docs.perl6.org/language/regexes#Wildcards_and_character_classes , the author did not have to escape the quotation mark; however, I do have to escape for it to work, <-[\\"]> , i.e., escape \ and escape ". What did I misunderstand?
Thanks !!
You don't need to escape characters inside a character class specification, except the backslash itself: So specifying <-[\"]> is the same as <-["]>. And specifying <-[\\"]>, indicates all characters except \ and ".
However, there may be a simpler way for you: if you're looking for just a single (set of) character(s) in a string, there's contains:
my $y = "foo bar baz";
say $y.contains("oo"); # True
This bypasses all of the expensive regex / grammar machinery by using a single simple low-level string match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With