Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Nothing" in Lookaround terms [RAKU]

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?

like image 724
jakar Avatar asked Feb 27 '20 10:02

jakar


1 Answers

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.

like image 129
Jonathan Worthington Avatar answered Oct 18 '22 12:10

Jonathan Worthington