I was reading in regexes documemtation about "Tilde for nesting structures".
The sideline explanation about the use of <?>
is:
Here
<?>
successfully matches the null string.
I assumed that I was able to use <?[]>
instead of it, but it failed to do so!
As an example:
say so "" ~~ / <?> /;
say so "test" ~~ / <?> /;
say so "" ~~ / <?[]> /;
say so "test" ~~ / <?[]> /;
The response:
True
True
False
False
Could someone give me an explanation about this?
The syntax <?[]>
means a lookahead matching an empty character class. Observe that an empty character class also never matches:
say "x" ~~ /<[]>/ # Nil
A character class specifies a set of characters that could be matched. An empty character class implies an empty set of characters, and so cannot possibly match anything.
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