Reputation: 1701
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?
Upvotes: 5
Views: 108
Reputation: 29454
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.
Upvotes: 10