Raku rules are the regular expression, string matching and general-purpose parsing facility of the Raku programming language, and are a core part of the language. Since Perl's pattern-matching constructs have exceeded the capabilities of formal regular expressions for some time, Raku documentation refers to them exclusively as regexes, distancing the term from the formal definition. Raku provides a superset of Perl 5 features with respect to regexes, folding them into a larger framework called rules, which provide the capabilities of a parsing expression grammar, as well as acting as a closure with respect to their lexical scope. Rules are introduced with the rule keyword, which has a usage quite similar to subroutine definitions. Anonymous rules can be introduced with the regex (or rx) keyword, or simply be used inline as regexes were in Perl 5 via the m (matching) or s (substitution) operators. In Apocalypse 5, a document outlining the preliminary design decisions for Raku pattern matching, Larry Wall enumerated 20 problems with the "current regex culture". Among these were that Perl's regexes were "too compact and 'cute'", had "too much reliance on too few metacharacters", "little support for named captures", "little support for grammars", and "poor integration with 'real' language". Between late 2004 and mid-2005, a compiler for Raku style rules was developed for the Parrot virtual machine called Parrot Grammar Engine (PGE), which was later renamed to the more generic Parser Grammar Engine. PGE is a combination of runtime and compiler for Raku style grammars that allows any parrot-based compiler to use these tools for parsing, and also to provide rules to their runtimes. Among other Raku features, support for named captures was added to Perl 5.10 in 2007. In May 2012, the reference implementation of Raku, Rakudo, shipped its Rakudo Star monthly snapshot with a working JSON parser built entirely in Raku rules. There are only six unchanged features from Perl 5's regexes: Literals: word characters (letters, numbers and underscore) matched literally Capturing: (.
Mathieu Hursin, Hakim Ferroukhi, Alexander Vasiliev