Synopsis_05 - Rules



NAME

Synopsis_05 - Rules


AUTHORS

Damian Conway <damian@conway.org> and Allison Randal <al@shadowed.net>


VERSION

   Maintainer: Patrick Michaud <pmichaud@pobox.com>
   Date: 24 Jun 2002
   Last Modified: 25 Feb 2006
   Number: 5
   Version: 12

This document summarizes Apocalypse 5, which is about the new regex syntax. We now try to call them ``rules'' because they haven't been regular expressions for a long time. (The term ``regex'' is still acceptable.)


New match state and capture variables

The underlying match state object is now available as the $/ variable, which is implicitly lexically scoped. All access to the current (or most recent) match is through this variable, even when it doesn't look like it. The individual capture variables (such as $0, $1, etc.) are just elements of $/.

By the way, the numbered capture variables now start at $0, $1, $2, etc. See below.


Unchanged syntactic features

The following regex features use the same syntax as in Perl 5:


Modifiers


Changed metacharacters


New metacharacters


Bracket rationalization


Variable (non-)interpolation


Extensible metasyntax (<...>)


Backslash reform


Regexes are rules


Backtracking control


Named Regexes


Nothing is illegal


Return values from matches

Match objects

Subpattern captures

Accessing captured subpatterns

Nested subpattern captures

Quantified subpattern captures

Indirectly quantified subpattern captures

Subpattern numbering

Subrule captures

Accessing captured subrules

Repeated captures of the same subrule

Aliasing

Aliases can be named or numbered. They can be scalar-, array-, or hash-like. And they can be applied to either capturing or non-capturing constructs. The following sections highlight special features of the semantics of some of those combinations.

Named scalar aliasing to subpatterns

Named scalar aliases applied to non-capturing brackets

Named scalar aliasing to subrules

Numbered scalar aliasing

Scalar aliases applied to quantified constructs

Array aliasing

Hash aliasing

External aliasing

Capturing from repeated matches

:keepall


Grammars


Syntactic categories

For writing your own backslash and assertion rules or macros, you may use the following syntactic categories:

     rule rxbackslash:<w> { ... }    # define your own \w and \W
     rule rxassertion:<*> { ... }    # define your own <*stuff>
     macro rxmetachar:<,> { ... }    # define a new metacharacter
     macro rxmodinternal:<x> { ... } # define your own /:x() stuff/
     macro rxmodexternal:<x> { ... } # define your own m:x()/stuff/

As with any such syntactic shenanigans, the declaration must be visible in the lexical scope to have any effect. It's possible the internal/external distinction is just a trait, and that some of those things are subs or methods rather than rules or macros. (The numeric rxmods are recognized by fallback macros defined with an empty operator name.)


Pragmas

The rx pragma may be used to control various aspects of regex compilation and usage not otherwise provided for.


Transliteration


Matching against non-strings

 Synopsis_05 - Rules