0% found this document useful (0 votes)
137 views1 page

Davechild Regular-Expressions PDF

The document provides a cheat sheet summarizing common elements of regular expressions including anchors, quantifiers, groups/ranges, character classes, escape sequences, modifiers, assertions, replacements, and special characters. It explains what each element means and provides examples. The cheat sheet is intended to serve as a concise reference for regular expressions.

Uploaded by

Krishna Foru
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)
137 views1 page

Davechild Regular-Expressions PDF

The document provides a cheat sheet summarizing common elements of regular expressions including anchors, quantifiers, groups/ranges, character classes, escape sequences, modifiers, assertions, replacements, and special characters. It explains what each element means and provides examples. The cheat sheet is intended to serve as a concise reference for regular expressions.

Uploaded by

Krishna Foru
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/ 1

Regular Expressions Cheat Sheet

Regular Expressions Anchors ^ \A $ \Z \b \B \< \> Start of string, or start of line in multi-line pattern Start of string End of string, or end of line in multi-line pattern End of string Word boundary Not word boundary Start of word End of word Regular Expressions Quantifiers * + ? {3} {3,} {3,5} 0 or more 1 or more 0 or 1 Exactly 3 3 or more 3, 4 or 5

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


Regular Expressions Groups and Ranges . (a|b) (...) (?:...) [abc] [^abc] [a-q] [A-Q] Regular Expressions Escape Sequences Regular Expressions 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 \ \Q \E Escape following character Begin literal sequence End literal sequence Regular Expressions 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 [0-7] \n Any character except new line (\n) a or b Group Passive (non-capturing) group Range (a or b or c) Not a or b or c Letter from a to q Upper case letter from A to Q Digit from 0 to 7 nth group/subpattern

Add a ? to a quantifier to make it ungreedy.

Ranges are inclusive.

"Escaping" is a way of treating characters which have a special meaning in regular expressions literally, rather than as special characters. Regular Expression Common Metacharacters ^ $ ( [ { \ | > . * + ?

Regular Expressions 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

) <

Regular Expressions String Replacement $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

The escape character is usually the backslash - \. Regular Expressions Special Characters \n \r \t \v \f \xxx \xhh New line Carriage return Tab Vertical tab Form feed Octal character xxx Hex character hh

Some regex implementations use \ instead of $.

Regular Expressions Assertions ?= ?! ?<= ?!= or ?<! ?> ?() ?()| ?# Cheatographer Dave Child (DaveChild) cheatography.com/davechild/ www.addedbytes.com Lookahead assertion Negative lookahead Lookbehind assertion Negative lookbehind Once-only Subexpression Condition [if then] Condition [if then else] Comment Cheat Sheet This cheat sheet was published on 19th October, 2011 and was last updated on 14th November, 2012. Sponsor FeedbackFair , increase your conversion rate today! Try it free! http://www.FeedbackFair.com

You might also like