- Perl provides lot of short cut notations to write regular expressions. These short cut notations help us to understand the regex easily and write smaller regular expressions. List of short cut notations. W - Match a 'word' character ( alphanumeric & ) 2. W - Match a non-word character.
- Quick-Start: Regex Cheat Sheet. The tables below are a reference to basic regex. While reading the rest of the site, when in doubt, you can always come back and look here. (It you want a bookmark, here's a direct link to the regex reference tables ). I encourage you to print the tables so you have a cheat sheet on your desk for quick reference.
- Perl Cheat Sheet html (juerd.nl) Perl Quick Reference Card pdf (johnbokma.com) Perl Regular Expressions by Iain Truskett pdf (refcards.com) Perl Regular Expression - Quick Reference pdf Perl Predefined Variables (perl's special variable cheat sheet) by Peteris Krumins doc, pdf (catonmat.net) Perl pack/unpack Summary (perl's pack.
PrevNext
– Perl Regular Expressions Tip Sheet. Compile Perl regular expression perl-regex and return regex-id to be used by other PRX functions. pos = prxmatch.
Pcre Cheat Sheet
When learning regexes, or when you need to use a feature you have not used yet or don't use often, itcan be quite useful to have a place for quick look-up. I hope this Regex Cheat-sheet will provide such aid for you.
Character Classes
Regex Character Classes and Special Character classes.
TODO: add examples w and d matching unicode letters and numebers.
Quantifiers
'Quantifier-modifier' aka. Minimal Matching
Other
Grouping and capturing
Anchors
Modifiers

Extended
Other Regex related articles
Official documentation
Published on 2015-08-19
Comments
In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.Please enable JavaScript to view the comments powered by Disqus.comments powered by DisqusThis document presents a tabular summary of the regular expression (regexp) syntax in Perl, then illustrates it with a collection of annotated examples.
| Metacharacters
 To present a metacharacter as a data character standing for itself, precede it with  In the table above, the characters themselves, in the first column, are links to descriptions of characters in my The ISO Latin 1 character repertoire - a description with usage notes. Note that the physical appearance (glyph) of a character may vary from one device or program or font to another. | Repetition
 Read the notation a’s as “occurrences of strings, each of which matches the pattern a”. Read repetition as any of the repetition expressions listed above it. Shortest match means that the shortest string matching the pattern is taken. The default is “greedy matching”, which finds the longest match. The repetition | 
Special notations with 
| 
 | 
 | 
| w | matches any single character classified as a “word” character (alphanumeric or “ _”) | 
| W | matches any non-“word” character | 
| s | matches any whitespace character (space, tab, newline) | 
| S | matches any non-whitespace character | 
| d | matches any digit character, equiv. to [0-9] | 
| D | matches any non-digit character | 
Character sets: specialities inside [...]
Different meanings apply inside a character set (“character class”) denoted by [...] so that, instead of the normal rules given here, the following apply:
| [characters] | matches any of the characters in the sequence | 
| [x-y] | matches any of the characters from x to y (inclusively) in the ASCII code | 
| [-] | matches the hyphen character “ -” | 
| [ n] | matches the newline; other single character denotations with apply normally, too | 
| [^something] | matches any character except those that [something]denotes; that is, immediately after the leading “[”, the circumflex “^” means “not” applied to all of the rest | 
Regular Expressions In Perl - A Summary With Examples
Examples
| expression | matches... | 
|---|---|
| abc | abc(that exact character sequence, but anywhere in the string) | 
| ^abc | abcat the beginning of the string | 
| abc$ | abcat the end of the string | 
| a|b | either of aandb | 
| ^abc|abc$ | the string abcat the beginning or at the end of the string | 
| ab{2,4}c | an afollowed by two, three or fourb’s followed by ac | 
| ab{2,}c | an afollowed by at least twob’s followed by ac | 
| ab*c | an afollowed by any number (zero or more) ofb’s followed by ac | 
| ab+c | an afollowed by one or moreb’s followed by ac | 
| ab?c | an afollowed by an optionalbfollowed by ac; that is, eitherabcorac | 
| a.c | an afollowed by any single character (not newline) followed by ac | 
| a.c | a.cexactly | 
| [abc] | any one of a,bandc | 
| [Aa]bc | either of Abcandabc | 
| [abc]+ | any (nonempty) string of a’s,b’s andc’s(such asa,abba,acbabcacaa) | 
| [^abc]+ | any (nonempty) string which does not contain any of a,bandc(such asdefg) | 
| dd | any two decimal digits, such as 42; same as d{2} | 
| w+ | a “word”: a nonempty sequence of alphanumeric characters and low lines (underscores), such as fooand12bar8andfoo_1 | 
| 100s*mk | the strings 100andmkoptionally separated by any amount of white space (spaces, tabs, newlines) | 
| abcb | abcwhen followed by a word boundary (e.g. inabc!but not inabcd) | 
| perlB | perlwhen not followed by a word boundary (e.g. inperlertbut not inperl stuff) | 
Examples of simple use in Perl statements
These examples use very simple regexps only. The intent is just to show contexts where regexps might be used, as well as the effect of some “flags” to matching and replacements. Note in particular that matching is by default case-sensitive (Abc does not match abc unless specified otherwise).
s/foo/bar/;
 replaces the first occurrence of the exact character sequence foo in the “current string” (in special variable $_) by the character sequence bar; for example, foolish bigfoot would become barlish bigfoot
s/foo/bar/g;
 replaces any occurrence of the exact character sequence foo in the “current string” by the character sequence bar; for example, foolish bigfoot would become barlish bigbart
s/foo/bar/gi;
 replaces any occurrence of foocase-insensitively in the “current string” by the character sequence bar (e.g. Foo and FOO get replaced by bar too) 
Regular Expression Cheat Sheet

if(m/foo/)...
 tests whether the current string contains the string foo
Date of creation: 2000-01-28. Last revision: 2007-04-16. Last modification: 2007-05-28.
Finnish translation – suomennos: Säännölliset lausekkeet Perlissä.
The inspiration for my writing this document was Appendix : A Summary of Perl Regular Expressions in Pankaj Kamthan’s CGI Security : Better Safe than Sorry, and my own repeated failures to memorize the syntax.
