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

Regular Expressions Cheat Sheet

This document provides a regular expressions cheat sheet with descriptions and examples of common regex patterns and characters. It explains what regular expressions are and how they can be used to match text strings. The cheat sheet defines special characters and constructs like periods, asterisks, question marks, brackets, pipes and more that have specific regex meanings for repeating, making optional, grouping and alternation. It also shows how to match word boundaries, whitespace, digits and other character classes.

Uploaded by

tibork1
Copyright
© © All Rights Reserved
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)
964 views2 pages

Regular Expressions Cheat Sheet

This document provides a regular expressions cheat sheet with descriptions and examples of common regex patterns and characters. It explains what regular expressions are and how they can be used to match text strings. The cheat sheet defines special characters and constructs like periods, asterisks, question marks, brackets, pipes and more that have specific regex meanings for repeating, making optional, grouping and alternation. It also shows how to match word boundaries, whitespace, digits and other character classes.

Uploaded by

tibork1
Copyright
© © All Rights Reserved
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

Make Tech Easier

Regular Expressions Cheat Sheet

Uncomplicating the complicated

A regular expression is a specific pattern used in computing that provides concise and flexible means to "match"
(specify and recognize) strings of text, such as particular characters, words, or patterns of characters. Common
abbreviations for "regular expression" include regex and regexp.
Wikipedia

Character

Description

Example

. (dot)

Match any single


character, except newline c.t matches "cat", "cut" or "cot."
(\n)

* (star)

Repeat the previous


expression 0 or more
times (greedy mode)

+ (plus)

Repeat the previous


expression 1 or more
times.

12+3 matches "123","1223","12223"

? (question
mark)

Makes the previous item


optional.

ma?ke matches "make", "mke"

^ (caret)

Match from the beginning


^he matches "hello", "hell", "help", "he is a boy"
of the string

$ (dollar)

Match from the end of the


ed$ matches "acted", bed", "greed"
string

(...) (round
bracket)

Grouping of characters or
(ak) matches "make", "take", '
expression

12*3 matches "13", "123", "1223", "12223".


It can be used together with . (dot) such as m.*easier to
match "maketecheasier".

{n} (curly
Match the previous item
bracket, where
exactly n times
n >= 1)

12{3}5 matches "12225"

{n,m} (n >=1, Match the previous item


between n and m times
m > n)

12{3,5}3 matches 12223, 122223, 1222223

{n,} (n >=1)

Match the previous item at


12{2,}3 matches 1223, 12223, 122223
least n times

[...] (square match any single


character in the bracket
bracket)

a[BC]d matches aBcd or abCd

[^...]

Match any character


except for those that are
defined in the bracket

a[^b]c matches "aec", "acc", "adc", but not "abc"

| (pipe)

Match either the


expression on the left or
right of the pipe.

col(o|ou)r matches "color", "colour"

- (hypen)

Specify a range of
[a-z] matches all lowercase alphabet.
characters to match. Used
[A-Z] matches all uppercase alphabet.
mostly with square
[0-9] matches all the digit 0 to 9.
bracket.

\ (backslash)

Escape a special

a\*c matches "a*c".

Property of Make Tech Easier (http://maketecheasier.com)

Character

Description

Example

character
\n, \r,
\t,\d,
\w,\s

match a newline, return,


tab, digit, word,
whitespace character
respectively

\D, \W, \S

Negate version of \d,


\w, \s. Match (not digit),
(not word), (not
whitespace) character
respectively.

\b...\b

Match a string at the


\bTech\b matches the word "Tech" in the phrase "Make
boundary Can be used to
Tech Easier".
match a word in a phrase.

\B...\B

Match a string not within


the boundary. Can be ued \BTech\B matches Tech in MakeTechEasier, but not in
to match a string within
Make Tech Easier.
another string

[\b]

When used inside a


square bracket, \b
matches a backspace
character

Do you like this cheat sheet?


Visit MakeTechEasier.com for more useful tech tutorials, tips and tricks

Property of Make Tech Easier (http://maketecheasier.com)

You might also like