Home Perl Regex


\ Quote the next metacharacter
^ Match the beginning of the line
. Match any character (except newline)
$ Match the end of the line (or before newline at the end)
| Alternation
() Grouping
[] Character class
* Match 0 or more times
*? Lazy quantifier
+ Match 1 or more times
+? Lazy quantifier
? Match 1 or 0 times
?? Lazy quantifier
{n} Match exactly n times
{n}? Lazy quantifier
{n,} Match at least n times
{n,}? Lazy quantifier
{n,m} Match at least n but not more than m times
{n,m}? Lazy quantifier
\t gorizontal tab
\n newline
\r return
\f form feed
\a alarm (bell)
\e escape
\033 octal escape
\x1B hex char
\x{263a} wide hex char
\c[ control char
\N{name} named char
\l lowercase next char
\u uppercase next char
\L lowercase till \E
\U uppercase till \E
\E end case modification
\Q quote (disable) pattern metacharacters till \E
\w Match a "word" character (alphanumeric plus "_")
\W Match a non-word character
\s Match a whitespace character
\S Match a non-whitespace character
\d Match a digit character
\D Match a non-digit character
\pP Match P, named property. Use \p{Prop} for longer names.
\PP Match non-P
\X Match eXtended Unicode "combining character sequence", equivalent to C<(?:\PM\pM*)>
\C Match a single C char (octet) even under utf8.
\b Match a word boundary
\B Match a non-(word boundary)
\A Match only at beginning of string
\Z Match only at end of string, or before newline at the end
\z Match only at end of string
\G Match only at pos() (e.g. at the end-of-match position of prior m//g)
(?=...) Positive Lookahead
(?!...) Negative Lookahead
(?<=...) Positive Lookbehind
(?<!...) Negative Lookbehind
(?xsmi-xsmi:) Mode modifiers
(?#...) Comments
(...) Capturing parentheses
(?:...) Grouping-only parentheses
(?>...) Atomic grouping
(? ( if ) then ) Embedded condition(s)
(? ( if ) then | else ) Embedded condition(s)
(?{...}) Embedded code
(??{...}) Dynamic regex

POSIX Bracket Expressions

Class Matching Characters
[:alnum:]Alphanumeric characters
[:alpha:]Alphabetic characters
[:blank:]Space and tab characters
[:cntrl:]Control characters
[:graph:]Printable and visible (non-space) characters
[:lower:]Lowercase characters
[:print:]Printable characters (includes whitespace)
[:punct:]Punctuation characters
[:space:]Whitespace characters
[:upper:]Uppercase characters
[:xdigit:]Hexadecimal digits