Sie sind auf Seite 1von 1

Perl Regular Expression Quantifiers: Metaquote & case translations:

Quick Reference 1.05 These quantifiers apply to the preceding atom. \Q Quote (de-meta) characters until \E
\U Uppercase characters until \E
* Match 0 or more times \L Lowercase characters until \E
N.B.: this quick reference is just that - some of the explanations
have been simplified. For the authoritative documentation, see the + Match 1 or more times
latest edition of Programming Perl or perldoc perlre. ? Match 0 or 1 times
{N} Match exactly N times Special variables:
{N,} Match at least N times
Specific characters: {N,M } Match at least N but not more than $` The characters to the left of the match
M times $& The characters that matched
\t A tab character $’ The characters to the right of the match
\n A newline character (OS neutral) By default, quantifiers are “greedy”. They \N The characters captured by the Nth set of
\r A carriage return character attempt to match as many characters as parentheses (if on the match side)
\f A form feed character possible. In order to make them match as few $N The characters captured by the Nth set of
\cX Control character CTRL-X characters as possible, follow them with a parentheses (if not on the match side)
\NNN Octal code for character NNN question mark “?”.

Modifiers:
Metacharacters: Character class metacharacters:
These modifiers apply to the entire pattern
The following 12 characters need to be escaped ^ If the first character of a class, negates
with a backslash - “\” - because by default, that class /i Ignore case
they mean something special. - Unless first or last character of a class, /g Match globally (all)
used for a range /m Let ^ and $ match next to embedded \n
\ | ( ) [ { ^ $ * + ? .
/s Let . match \n
. /x Ignore most whitespace and allow
Match any one character (except \n) Character class shortcuts: comments
| Alternation
/e Evaluate right hand side of s/// as an
( ) Group and capture \d [0-9] A digit
[ ] expression
Define character class \D [^0-9] A non-digit
\ Modify the meaning of the next char. \s [ \t\n\r\f] A whitespace char. All except /e apply to both m// and s/// .
\S [^ \t\n\r\f] A non-whitespace
char.
Anchors: \w [a-zA-Z0-9_] A ‘word’ char.
Binding operators:
\W [^a-zA-Z0-9_] A ‘non-word’ char.
^ Match at the beginning of a string (or
=~ True if the regex matches
line)
!~ True if the regex doesn’t match
$ Match at the end of a string (or line) These shortcuts can be used either on their own,
\b Match at a ‘word’ boundary or within a character class.
\B Match at not a ‘word’ boundary
This information is offered in good faith and in the hope that it may
These are also known as zero width assertions. Copyright © 2002 by Stephen B. Jenkins. http://www.erudil.com be of use, but is not guaranteed to be correct, up to date, or suitable
All rights reserved. This is free documentation; you can copy and/or for any particular purpose whatsoever. The author accepts no
redistribute it under the same terms as Perl itself. liability in respect of this information or its use.