0% found this document useful (0 votes)
115 views2 pages

Regular Expressions Cheatsheet

This document is a cheat sheet for regular expressions that provides descriptions and examples of common regex patterns and constructs. It covers patterns that match the beginning or end of strings, single characters, character classes, quantifiers, groups, character types, delimiters, and word boundaries. For example, it explains that ^ matches the beginning of a string, $ matches the end, . matches any single character, and * matches the preceding item zero or more times.

Uploaded by

lckim
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views2 pages

Regular Expressions Cheatsheet

This document is a cheat sheet for regular expressions that provides descriptions and examples of common regex patterns and constructs. It covers patterns that match the beginning or end of strings, single characters, character classes, quantifiers, groups, character types, delimiters, and word boundaries. For example, it explains that ^ matches the beginning of a string, $ matches the end, . matches any single character, and * matches the preceding item zero or more times.

Uploaded by

lckim
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

12/2/11 Regular Epressions Cheat Sheet

1/2 krijnhoetmer.nl/stuff/rege/cheat-sheet/
Regular Epressions Cheat Sheet
^ The pattern has to appear at the begInnIng of a strIng. ^cat matches any strIng that begIns wIth cat
$ The pattern has to appear at the end of a strIng. cat$ matches any strIng that ends wIth cat
. |atches any character. cat. matches catT and cat2 but not catty
[] 8racket expressIon. |atches one of any characters enclosed. gr[ae]y matches gray or grey
[^]
Negates a bracket expressIon. |atches one of any characters EXCEPT those
enclosed.
1[^02] matches 13 but not 10 or 12
[] Fange. |atches any characters wIthIn the range. [19] matches any sIngle dIgIt EXCEPT 0
? PreceedIng Item must match one or zero tImes.
colou?r matches color or colour but not
colouur
+ PreceedIng Item must match one or more tImes. be+ matches be or bee but not b
* PreceedIng Item must match zero or more tImes. be* matches b or be or beeeeeeeeee
() Parentheses. Creates a substrIng or Item that metacharacters can be applIed toa(bee)?t matches at or abeet but not abet
n 8ound. SpecIfIes exact number of tImes for the preceedIng Item to match. [09]3 matches any three dIgIts
n, 8ound. SpecIfIes mInImum number of tImes for the preceedIng Item to match. [09]3, matches any three or more dIgIts
n,m
8ound. SpecIfIes mInImum and maxImum number of tImes for the preceedIng
Item to match.
[09]3,5 matches any three, four, or fIve
dIgIts
AlternatIon. Dne of the alternatIves has to match.
July(first1st1) wIll match July1st but
not July2
POSIX Character Classes
[:alnum:] alphanumerIc character [[:alnum:]]3 matches any three letters or numbers, lIke 7Ds
[:alpha:] alphabetIc character, any case
[[:alpha:]]5 matches fIve alphabetIc characters, any case,
lIke aBcDe
[:blank:] space and tab
[[:blank:]]3,5 matches any three, four, or fIve spaces and
tabs
[:digit:] dIgIts
[[:digit:]]3,5 matches any three, four, or fIve dIgIts, lIke 3,
05, 489
[:lower:] lowercase alphabetIcs [[:lower:]] matches a but not A
[:punct:] punctuatIon characters [[:punct:]] matches ! or . or , but not a or 3
[:space:]
all whItespace characters, IncludIng newlIne and
carrIage return
[[:space:]] matches any space, tab, newlIne, or carrIage
return
[:upper:] uppercase alphabetIcs [[:upper:]] matches A but not a
Perl-Stle Metacharacters
// 0efault delImIters for pattern /colou?r/ matches color or colour
i Append to pattern to specIfy a case InsensItIve match /colou?r/i matches COLOR or Colour
\b A word boundary, the spot between word (\w) and nonword (\W) characters /\bfred\b/i matches Fred but not Alfred or Frederick
\B A nonword boundary /fred\B/i matches Frederick but not Fred
\d A sIngle dIgIt character /a\db/i matches a2b but not acb
\D A sIngle nondIgIt character /a\Db/i matches aCb but not a2b
\n The newlIne character. (ASC 10) /\n/ matches a newlIne
\r The carrIage return character. (ASC 1J) /\r/ matches a carrIage return
\s A sIngle whItespace character /a\sb/ matches ab but not ab
12/2/11 Regular Epressions Cheat Sheet
2/2 krijnhoetmer.nl/stuff/rege/cheat-sheet/
\S A single non-hitespace character /a\Sb/ matches a2b but not ab
\t The tab character. (ASCII 9) /\t/ matches a tab.
\ A single ord character - alphanumeric and underscore /\/ matches 1 or _ but not ?
\W A single non-ord character /a\Wb/i matches a!b but not a2b

You might also like