11.2.2  Perl5 Regular Expression Syntax

The supported meta characters are:

.Match any character but newline.
\Quote the next metacharacter.
^Match the beginning of the line.
$Match the end of the line (or before newline at the end).
[]Character class.

The following standard escapes are recognized:


The following Perl-defined zero-width assertions are supported:

\A Match only at beginning of string.
\b Match a word boundary.
\B Match a non-word boundary.
\z Match only at end of string.
\Z Match only at end of string, or before newline at the end.

The following standard character classes are recognized:

\wWord: [A-Za-z0-9_].

The following standard quantifiers are recognized:

*Match 0 or more times.
+Match 1 or more times.
?Match 1 or 0 times.
{ n }Match exactly n times.
{ n,}Match at least n times.
{ n, m }Match at least n but not more than m times.

Back References

Back-references like \1 match whatever the corresponding group (parenthesized regular expression component) matched. For example the regular expression


matches repeated strings like


Allen’s comments also document support for:

\033Octal char.
\x1BHex char.
\x { 263a }Wide hex char. (Unicode SMILEY)
\c[ Control char.
\L Lowercase until \E. (Think vi.)
\U Uppercase until \E. (Think vi.)
\E End case modification. (Think vi.)
\Q Quote (disable) pattern metacharacters until next \E.
\pP Match P, named property. Use \p { Prop } for longer names.
\PP Match non-P.
\C Match a single C char (octet) even under utf8.

Code comments document the following as implemented by the parser but not by the regular expression engine proper:

\N { name }Named char.
\l Lowercase next char. (Think vi.)
\u Uppercase next char. (Think vi.)

There is currently no locale support — feel free to contribute this!

Comments and suggestions to: