Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Regular Expressions Cheat Sheet: Main Concepts, Cheat Sheet of Javascript programming

This document contains a quick overview on the Regular Expression

Typology: Cheat Sheet

2019/2020

Uploaded on 10/09/2020

picoo
picoo 🇮🇳

4.5

(13)

235 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Metacharacters (must be escaped)
^
$
(
)
<
.
*
+
?
[
{
\
|
>
Escape Character
\Escape Character
Quantifiers
*
+
?
{3}
{3,}
{3,5}
0 or more
1 or more
0 or 1
Exactly 3
3 or more
3, 4 or 5
Quantifier Modifiers
"x" below represents a quantifier
x?
Ungreedy version of "x"
Anchors
^
\A
$
\Z
\b
\B
\<
\>
Start of string
Start of string
End of string
End of string
Word boundary
Not word boundary
Start of word
End of word
POSIX
[:upper:]
[:lower:]
[:alpha:]
[:alnum:]
[:digit:]
[:xdigit:]
[:punct:]
[:blank:]
[:space:]
[:cntrl:]
[:graph:]
[:print:]
[:word:]
Upper case letters
Lower case letters
All letters
Digits and letters
Digits
Hexadecimal digits
Punctuation
Space and tab
Blank characters
Control characters
Printed characters
Printed characters and
spaces
Digits, letters and
underscore
Character Classes
\c
\s
\S
\d
\D
\w
\W
\x
\O
Control character
White space
Not white space
Digit
Not digit
Word
Not word
Hexadecimal digit
Octal digit
Special Characters
\n
\r
\t
\v
\f
\xxx
\xhh
New line
Carriage return
Tab
Vertical tab
Form feed
Octal character xxx
Hex character hh
Pattern Modifiers
g
i
m
s
x
e
U
Global match
Case-insensitive
Multiple lines
Treat string as single line
Allow comments and
white space in pattern
Evaluate replacement
Ungreedy pattern
Available free from
AddedBytes.com
Assertions
?=
?!
?<=
?!= or ?<!
?>
?()
?()|
?#
Lookahead assertion
Negative lookahead
Lookbehind assertion
Negative lookbehind
Once-only Subexpression
Condition [if then]
Condition [if then else]
Comment
String Replacement (Backreferences)
$n
$2
$1
$`
$'
$+
$&
nth non-passive group
"xyz" in /^(abc(xyz))$/
"xyz" in /^(?:abc)(xyz)$/
Before matched string
After matched string
Last matched string
Entire matched string
Groups and Ranges
.
(a|b)
(...)
(?:...)
[abc]
[^abc]
[a-q]
[A-Q]
[0-7]
\n
Note: Ranges are inclusive.
Any character except
new line (\n)
a or b
Group
Passive Group
Range (a or b or c)
Not a or b or c
Letter between a and q
Upper case letter
between A and Q
Digit between 0 and 7
nth group/subpattern
Sample Patterns
Pattern
([A-Za-z0-9-]+)
(\d{1,2}\/\d{1,2}\/\d{4})
([^\s]+(?=\.(jpg|gif|png))\.\2)
(^[1-9]{1}$|^[1-4]{1}[0-9]{1}$|^50$)
(#?([A-Fa-f0-9]){3}(([A-Fa-f0-9]){3})?)
((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,15})
(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})
(\<(/?[^\>]+)\>)
Note: These patterns are intended for reference purposes and have not been
extensively tested. Please use with caution and test thoroughly before use.
Will Match
Letters, numbers and hyphens
Date (e.g. 21/3/2006)
jpg, gif or png image
Any number from 1 to 50 inclusive
Valid hexadecimal colour code
String with at least one upper case
letter, one lower case letter, and one
digit (useful for passwords).
Email addresses
HTML Tags

Partial preview of the text

Download Regular Expressions Cheat Sheet: Main Concepts and more Cheat Sheet Javascript programming in PDF only on Docsity!

Metacharacters (must be escaped)

^ $ ( ) <

[

\

Escape Character

\ Escape Character

Quantifiers

? {3} {3,} {3,5}

0 or more 1 or more 0 or 1 Exactly 3 3 or more 3, 4 or 5

Quantifier Modifiers

"x" below represents a quantifier x? Ungreedy version of "x"

Anchors

^ \A $ \Z \b \B < >

Start of string Start of string End of string End of string Word boundary Not word boundary Start of word End of word

POSIX

[:upper:] [:lower:] [:alpha:] [:alnum:] [:digit:] [:xdigit:] [:punct:] [:blank:] [:space:] [:cntrl:] [:graph:] [:print:]

[:word:]

Upper case letters Lower case letters All letters Digits and letters Digits Hexadecimal digits Punctuation Space and tab Blank characters Control characters Printed characters Printed characters and spaces Digits, letters and underscore

Character Classes

\c \s \S \d \D \w \W \x \O

Control character White space Not white space Digit Not digit Word Not word Hexadecimal digit Octal digit

Special Characters

\n \r \t \v \f \xxx \xhh

New line Carriage return Tab Vertical tab Form feed Octal character xxx Hex character hh

Pattern Modifiers

g i m s x e U Global match Case-insensitive Multiple lines Treat string as single line Allow comments and white space in pattern Evaluate replacement Ungreedy pattern

Available free from AddedBytes.com

Assertions

?= ?! ?<= ?!= or ?<! ?> ?() ?()| ?#

Lookahead assertion Negative lookahead Lookbehind assertion Negative lookbehind Once-only Subexpression Condition [if then] Condition [if then else] Comment

String Replacement (Backreferences)

$n $ $ $` $' $+ $&

nth non-passive group "xyz" in /^(abc(xyz))$/ "xyz" in /^(?:abc)(xyz)$/ Before matched string After matched string Last matched string Entire matched string

Groups and Ranges

.

(a|b) (...) (?:...) [abc] [^abc] [a-q] [A-Q]

[0-7]

\n Note: Ranges are inclusive.

Any character except new line (\n) a or b Group Passive Group Range (a or b or c) Not a or b or c Letter between a and q Upper case letter between A and Q Digit between 0 and 7 nth group/subpattern

Sample Patterns

Pattern ([A-Za-z0-9-]+) (\d{1,2}/\d{1,2}/\d{4}) ([^\s]+(?=.(jpg|gif|png)).\2) (^[1-9]{1}$|^[1-4]{1}[0-9]{1}$|^50$) (#?([A-Fa-f0-9]){3}(([A-Fa-f0-9]){3})?) ((?=.\d)(?=.[a-z])(?=.*[A-Z]).{8,15})

(\w+@[a-zA-Z_]+?.[a-zA-Z]{2,6}) (<(/?[^>]+)>)

Note: These patterns are intended for reference purposes and have not been extensively tested. Please use with caution and test thoroughly before use.

Will Match Letters, numbers and hyphens Date (e.g. 21/3/2006) jpg, gif or png image Any number from 1 to 50 inclusive Valid hexadecimal colour code String with at least one upper case letter, one lower case letter, and one digit (useful for passwords). Email addresses HTML Tags