Best way to make regex matching exactly null characters in Perl 6?

How to explicitly define regex(a numbered or named capture group) that always matches exactly zero characters?

> "abc" ~~ m/()abc/
===SORRY!=== Error while compiling:
Null regex not allowed

> my regex null {}
===SORRY!=== Error while compiling:
Null regex not allowed

> my regex null {<[]>}
regex null {<[]>}
> "abc" ~~ m/<null>abc/
False

Of course, I can use something like the following, but I'm looking for an idiomatic way to do this.

> my regex null {a ** 0}
regex null {a ** 0}
> "abc" ~~ m/<null>abc/
「abc」
 null => 「」

UPD: It works, but the best way?

> my regex null { '' }
regex null { '' }
> "abc" ~~ m/<null>abc/
「abc」
 null => 「」
> "abc" ~~ m/('') abc/
「abc」
 0 => 「」
+4
source share
1 answer

A statement that always wins and 0 corresponds to symbols as well: <?>.

For instance:

say so 'foo' ~~ / <?> 'foo' /;
# output: True

raiph, , , <!>. , , , . :

\d || [ { note "Error: the previous token must be followed by a number."; } <!> ]
+8

Source: https://habr.com/ru/post/1688283/


All Articles