SlideShare a Scribd company logo
1 of 1
Download to read offline
Regular Expressions Cheat Sheet

by Dave Child (DaveChild) via cheatography.com/1/cs/5/
Regular Expressions Anchors

Regular Expressions Quantifiers

Regular Expressions Groups and Ranges

^

Start of string, or start of line in multi-line pattern

*

0 or more

.

Any character except new line (n)

A

Start of string

+

1 or more

(a|b)

a or b

$

End of string, or end of line in multi-line pattern

?

0 or 1

(...)

Group

Z

End of string

{3}

Exactly 3

(?:...)

Passive (non-capturing) group

b

Word boundary

{3,}

3 or more

[abc]

Range (a or b or c)

B

Not word boundary

{3,5}

3, 4 or 5

[^abc]

Not a or b or c

<

Start of word

Add a ? to a quantifier to make it ungreedy.

[a-q]

Letter from a to q

>

End of word

[A-Q]

Upper case letter from A to Q

Regular Expressions Escape Sequences

[0-7]

Digit from 0 to 7

Regular Expressions Character Classes



Escape following character

n

nth group/subpattern

c

Control character

Q

Begin literal sequence

Ranges are inclusive.

s

White space

E

End literal sequence

S

Not white space

"Escaping" is a way of treating characters which have

Regular Expressions Pattern Modifiers

d

Digit

a special meaning in regular expressions literally,

g

Global match

D

Not digit

rather than as special characters.

i

Case-insensitive

w

Word

m

Multiple lines

W

Not word

s

Treat string as single line

x

Hexadecimal digit

x

Allow comments and white space in pattern

O

Octal digit

e

Evaluate replacement

U

Ungreedy pattern

Regular Expression Common Metacharacters
^

[

.

$

{

*

(



+

Regular Expressions POSIX

)

|

?

[:upper:]

Upper case letters

<

>

[:lower:]

Lower case letters

The escape character is usually the backslash - .

[:alpha:]

All letters

[:alnum:]

Digits and letters

[:digit:]

Digits

[:xdigit:]

Hexadecimal digits

[:punct:]

Punctuation

[:blank:]

Space and tab

[:space:]

Blank characters

[:cntrl:]

Control characters

[:graph:]

Printed characters

[:print:]

Printed characters and spaces

[:word:]

Digits, letters and underscore

Regular Expressions Special Characters
n

New line

r

Carriage return

t

Tab

v

Vertical tab

f

Form feed

xxx

Octal character xxx

xhh

Regular Expressions String Replacement
$n

nth non-passive group

$2

"xyz" in /^(abc(xyz))$/

$1

"xyz" in /^(?:abc)(xyz)$/

$`

Before matched string

$'

After matched string

$+

Last matched string

$&

Entire matched string

Hex character hh

Some regex implementations use  instead of $.

Regular Expressions Assertions
?=

Lookahead assertion

?!

Negative lookahead

?<=

Lookbehind assertion

?!= or ?<!

Negative lookbehind

?>

Once-only Subexpression

?()

Condition [if then]

?()|

Condition [if then else]

?#

Comment

Cheatographer

Cheat Sheet

Sponsor

Dave Child (DaveChild)

This cheat sheet was published on 19th October, 2011

FeedbackFair, increase your conversion rate today!

cheatography.com/davechild/

and was last updated on 14th November, 2012.

Try it free!

www.addedbytes.com

http://www.FeedbackFair.com

More Related Content

Viewers also liked

Celebrate big rewards
Celebrate big rewardsCelebrate big rewards
Celebrate big rewardsGrace Kennedy
 
Prácticas pedagogía natalia_chañe_tamayo_2_a
Prácticas pedagogía natalia_chañe_tamayo_2_aPrácticas pedagogía natalia_chañe_tamayo_2_a
Prácticas pedagogía natalia_chañe_tamayo_2_aNatalia Chañe Tamayo
 
O principio fundamental_da_dignidade_humana_e_sua_concretizacao_judicial
O principio fundamental_da_dignidade_humana_e_sua_concretizacao_judicialO principio fundamental_da_dignidade_humana_e_sua_concretizacao_judicial
O principio fundamental_da_dignidade_humana_e_sua_concretizacao_judicialGlauco de Oliveira
 
Hãy Phòng Bệnh Đúng Cách Để Góp Phần Giảm Tải Bệnh Viện !!!
Hãy Phòng Bệnh Đúng Cách Để Góp Phần Giảm Tải Bệnh Viện !!!Hãy Phòng Bệnh Đúng Cách Để Góp Phần Giảm Tải Bệnh Viện !!!
Hãy Phòng Bệnh Đúng Cách Để Góp Phần Giảm Tải Bệnh Viện !!!Cao Huu Hanh
 
HYDROLIFT 24, 2003, £49,995 For Sale Brochure. Presented By yachtingelite.com
HYDROLIFT 24, 2003, £49,995 For Sale Brochure. Presented By yachtingelite.comHYDROLIFT 24, 2003, £49,995 For Sale Brochure. Presented By yachtingelite.com
HYDROLIFT 24, 2003, £49,995 For Sale Brochure. Presented By yachtingelite.comWolfgang Stolle
 
これから始める人のための自動化入門 〜Ubuntu Jujuを使って〜
これから始める人のための自動化入門 〜Ubuntu Jujuを使って〜これから始める人のための自動化入門 〜Ubuntu Jujuを使って〜
これから始める人のための自動化入門 〜Ubuntu Jujuを使って〜VirtualTech Japan Inc.
 
Concreto armado antonio blanco blasco
Concreto armado   antonio blanco blascoConcreto armado   antonio blanco blasco
Concreto armado antonio blanco blascowallky8520
 

Viewers also liked (13)

Heridas y suturas
Heridas y suturasHeridas y suturas
Heridas y suturas
 
Celebrate big rewards
Celebrate big rewardsCelebrate big rewards
Celebrate big rewards
 
Prácticas pedagogía natalia_chañe_tamayo_2_a
Prácticas pedagogía natalia_chañe_tamayo_2_aPrácticas pedagogía natalia_chañe_tamayo_2_a
Prácticas pedagogía natalia_chañe_tamayo_2_a
 
Sida
SidaSida
Sida
 
O principio fundamental_da_dignidade_humana_e_sua_concretizacao_judicial
O principio fundamental_da_dignidade_humana_e_sua_concretizacao_judicialO principio fundamental_da_dignidade_humana_e_sua_concretizacao_judicial
O principio fundamental_da_dignidade_humana_e_sua_concretizacao_judicial
 
Gustavo lopez munevar hoja de vida
Gustavo lopez munevar hoja de vidaGustavo lopez munevar hoja de vida
Gustavo lopez munevar hoja de vida
 
Gestion y calidad de la educación
Gestion y  calidad de la educaciónGestion y  calidad de la educación
Gestion y calidad de la educación
 
Hãy Phòng Bệnh Đúng Cách Để Góp Phần Giảm Tải Bệnh Viện !!!
Hãy Phòng Bệnh Đúng Cách Để Góp Phần Giảm Tải Bệnh Viện !!!Hãy Phòng Bệnh Đúng Cách Để Góp Phần Giảm Tải Bệnh Viện !!!
Hãy Phòng Bệnh Đúng Cách Để Góp Phần Giảm Tải Bệnh Viện !!!
 
Il portogallo
Il portogalloIl portogallo
Il portogallo
 
Projectile motion
Projectile motionProjectile motion
Projectile motion
 
HYDROLIFT 24, 2003, £49,995 For Sale Brochure. Presented By yachtingelite.com
HYDROLIFT 24, 2003, £49,995 For Sale Brochure. Presented By yachtingelite.comHYDROLIFT 24, 2003, £49,995 For Sale Brochure. Presented By yachtingelite.com
HYDROLIFT 24, 2003, £49,995 For Sale Brochure. Presented By yachtingelite.com
 
これから始める人のための自動化入門 〜Ubuntu Jujuを使って〜
これから始める人のための自動化入門 〜Ubuntu Jujuを使って〜これから始める人のための自動化入門 〜Ubuntu Jujuを使って〜
これから始める人のための自動化入門 〜Ubuntu Jujuを使って〜
 
Concreto armado antonio blanco blasco
Concreto armado   antonio blanco blascoConcreto armado   antonio blanco blasco
Concreto armado antonio blanco blasco
 

Similar to fghfghf

Similar to fghfghf (9)

slide share test
slide share testslide share test
slide share test
 
mhg
mhgmhg
mhg
 
Regexps
RegexpsRegexps
Regexps
 
Expresiones Regulares
Expresiones RegularesExpresiones Regulares
Expresiones Regulares
 
Regex Cards - Powerpoint Format
Regex Cards - Powerpoint FormatRegex Cards - Powerpoint Format
Regex Cards - Powerpoint Format
 
An Introduction to Regular expressions
An Introduction to Regular expressionsAn Introduction to Regular expressions
An Introduction to Regular expressions
 
Regular expressions quick reference
Regular expressions quick referenceRegular expressions quick reference
Regular expressions quick reference
 
Regular expression
Regular expressionRegular expression
Regular expression
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 

More from Sanjulika Rastogi (20)

Using Proficiency Testing
Using Proficiency Testing Using Proficiency Testing
Using Proficiency Testing
 
WIDA CELLA
WIDA CELLAWIDA CELLA
WIDA CELLA
 
Using Proficiency Testing
Using Proficiency Testing Using Proficiency Testing
Using Proficiency Testing
 
Using Proficiency Testing
Using Proficiency Testing Using Proficiency Testing
Using Proficiency Testing
 
WIDA CELLA
WIDA CELLAWIDA CELLA
WIDA CELLA
 
Methods-Building Developmental Lessons
Methods-Building Developmental LessonsMethods-Building Developmental Lessons
Methods-Building Developmental Lessons
 
SLA Theories-Chapter 6
SLA Theories-Chapter 6SLA Theories-Chapter 6
SLA Theories-Chapter 6
 
Language Experience Lesson Activity
Language Experience Lesson ActivityLanguage Experience Lesson Activity
Language Experience Lesson Activity
 
Cooperative Learning Activity
Cooperative Learning ActivityCooperative Learning Activity
Cooperative Learning Activity
 
ganesh testing
ganesh testing ganesh testing
ganesh testing
 
ganesh testing
ganesh testing ganesh testing
ganesh testing
 
Test resource 2
Test resource 2Test resource 2
Test resource 2
 
Pop Tart Cat 3
Pop Tart Cat 3Pop Tart Cat 3
Pop Tart Cat 3
 
Resource Erin
Resource ErinResource Erin
Resource Erin
 
Resource Erin
Resource ErinResource Erin
Resource Erin
 
Test resource 2
Test resource 2Test resource 2
Test resource 2
 
Pop Tart Cat 3
Pop Tart Cat 3Pop Tart Cat 3
Pop Tart Cat 3
 
Pop Tart Cat 3
Pop Tart Cat 3Pop Tart Cat 3
Pop Tart Cat 3
 
Test resource 2
Test resource 2Test resource 2
Test resource 2
 
Resource Erin
Resource ErinResource Erin
Resource Erin
 

fghfghf

  • 1. Regular Expressions Cheat Sheet by Dave Child (DaveChild) via cheatography.com/1/cs/5/ Regular Expressions Anchors Regular Expressions Quantifiers Regular Expressions Groups and Ranges ^ Start of string, or start of line in multi-line pattern * 0 or more . Any character except new line (n) A Start of string + 1 or more (a|b) a or b $ End of string, or end of line in multi-line pattern ? 0 or 1 (...) Group Z End of string {3} Exactly 3 (?:...) Passive (non-capturing) group b Word boundary {3,} 3 or more [abc] Range (a or b or c) B Not word boundary {3,5} 3, 4 or 5 [^abc] Not a or b or c < Start of word Add a ? to a quantifier to make it ungreedy. [a-q] Letter from a to q > End of word [A-Q] Upper case letter from A to Q Regular Expressions Escape Sequences [0-7] Digit from 0 to 7 Regular Expressions Character Classes Escape following character n nth group/subpattern c Control character Q Begin literal sequence Ranges are inclusive. s White space E End literal sequence S Not white space "Escaping" is a way of treating characters which have Regular Expressions Pattern Modifiers d Digit a special meaning in regular expressions literally, g Global match D Not digit rather than as special characters. i Case-insensitive w Word m Multiple lines W Not word s Treat string as single line x Hexadecimal digit x Allow comments and white space in pattern O Octal digit e Evaluate replacement U Ungreedy pattern Regular Expression Common Metacharacters ^ [ . $ { * ( + Regular Expressions POSIX ) | ? [:upper:] Upper case letters < > [:lower:] Lower case letters The escape character is usually the backslash - . [:alpha:] All letters [:alnum:] Digits and letters [:digit:] Digits [:xdigit:] Hexadecimal digits [:punct:] Punctuation [:blank:] Space and tab [:space:] Blank characters [:cntrl:] Control characters [:graph:] Printed characters [:print:] Printed characters and spaces [:word:] Digits, letters and underscore Regular Expressions Special Characters n New line r Carriage return t Tab v Vertical tab f Form feed xxx Octal character xxx xhh Regular Expressions String Replacement $n nth non-passive group $2 "xyz" in /^(abc(xyz))$/ $1 "xyz" in /^(?:abc)(xyz)$/ $` Before matched string $' After matched string $+ Last matched string $& Entire matched string Hex character hh Some regex implementations use instead of $. Regular Expressions Assertions ?= Lookahead assertion ?! Negative lookahead ?<= Lookbehind assertion ?!= or ?<! Negative lookbehind ?> Once-only Subexpression ?() Condition [if then] ?()| Condition [if then else] ?# Comment Cheatographer Cheat Sheet Sponsor Dave Child (DaveChild) This cheat sheet was published on 19th October, 2011 FeedbackFair, increase your conversion rate today! cheatography.com/davechild/ and was last updated on 14th November, 2012. Try it free! www.addedbytes.com http://www.FeedbackFair.com