Metacharacters For Regular Expressions in Perl
Metacharacters For Regular Expressions in Perl
General metacharacters:
. any character (except \n)
( ) grouping, saving
\1, \2, etc. back-references to saved matches
| (pipe symbol) alternatives (generally inside parentheses)
Character classes:
[abcd], [A-Z] bracketed character class (any character in the bracket, within range)
[^abcd] negation of bracketed characters (any character not in the bracket)
\w any word character [A-Za-z0-9_]
\W any non-word character [^A-Za-z0-9_]
\d any digit [0-9]
\D any non-digit [^0-9]
\s any space character [\t\n\f\r ]
\S any non-space character [^\t\n\f\r ]
Anchors:
^ match start of string
$ match end of string
\b word boundary
\B non-word boundary
Quantifiers:
? 0 or 1
* 0 or more
+ 1 or more
{m,n} between m and n
{m,} at least m
{m} exactly m
Greediness of these quantifiers is turned off by a trailing "?" character:
??, *?, +?, {m,n}?, {m,}?
Modifiers:
i make matching case-insensitive
x ignore spaces (and newlines) in pattern
s also match \n for . in pattern
g match the complete string (continue searching after the first match)
Modifiers are entered after the pattern:
/pattern/ixsg