Regular Expression Full Cheatsheet Mind Map
Create Mind Map
Regular Expression FUll Cheatsheet (For quick look) :) note: for downloading visit https://buggyprogrammer.com/regular-expression-cheatsheet/ ------x-------------------x----------------x------------x----------------x------------- -------------- Anchors -------------- ^ → Start of string, or start of line in multiline pattern \A → Start of string $ → End of string, or end of line in multi-line pattern \Z → End of string \b → Word boundary \B → Not word boundary < → Start of word > → End of word ---------- Character Classes -------- \c → Control character \s → White space \S → Not white space \d → Digit \D → Not digit \w → Word \W → Not word \x → Hexadecimal digit \O → Octal digit --------- Quantifiers ----------------- → 0 or more {3} → Exactly 3 → 1 or more {3,} → 3 or more ? → 0 or 1 {3,5} → 3, 4 or 5 Add a ? to a quantifier to make it ungreedy. ------- Special Characters ------------- \n → New line \r → Carriage return \t → Tab \v → Vertical tab \f → Form feed \xxx → Octal character xxx \xhh → Hex character hh --------- Groups and Ranges ------------- . → Any character except new line (\n) (a|b) → a or b (...) → Group (?:...) → Passive (non-capturing) group [abc] → Range (a or b or c) [^abc] → Not (a or b or c) [a-q] → Lower case letter from a to q [A-Q] → Upper case letter from A to Q [0-7] → Digit from 0 to 7 \x → Group/subpattern number "x" Ranges are inclusive. ----------- Assertions --------------- ?= → Lookahead assertion ?! → Negative lookahead ?<= → Lookbehind assertion ?!= or ?<! → Negative lookbehind ?> → Once-only Subexpression ?() → Condition [if then] ?()| → Condition [if then else] ?# → Comment ------ Pattern Modifiers -------- g → Global match i* → Case-insensitive m* → Multiple lines s* → Treat string as single line x* → Allow comments and whitespace in pattern e* → Evaluate replacement U* → Ungreedy pattern * → PCRE modifier ------ 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 Some regex implementations use \ instead of $ ---------- Escape Sequences ------------ \ Escape following character \Q Begin literal sequence \E End literal sequence "Escaping" is a way of treating characters which have a special meaning in regular expressions literally, rather than as special characters. --------- Common Metacharacters --------- ^ [ . $ { * ( \ + ) | < The escape character is usually \ ------------ POSIX ---------------- [:upper:] → Upper case letters [:lower:] → Lower case letters [: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 Expression Full Cheatsheet
Anchors
Define positions within the string.
Start of String
^ matches the start of a string.
Example: ^hello matches any string that starts with "hello".
I've created a mind map based on the Regular Expression Full Cheatsheet. You can now visualize the key concepts and details effectively!
Here are some options to further engage with this content:
End of String
$ matches the end of a string.
Example: world$ matches any string that ends with "world".
Character Classes
Define sets of characters.
Word Characters
\w matches any word character (alphanumeric + underscore).
Example: \w+ matches "word" in "word123".
Digit Characters
\d matches any digit.
Example: \d{3} matches "123" in "abc123efg".
Whitespace Characters
\s matches any whitespace character.
Example: \s\w+ matches " white" in " black white".
Quantifiers
Specify quantity of preceding elements.
Zero or More
* matches 0 or more occurrences.
Example: ho* matches "h", "ho", "hoo", etc.
One or More
+ matches 1 or more occurrences.
Example: ho+ matches "ho" and "hoo".
Optional
? matches 0 or 1 occurrence.
Example: colou?r matches "color" and "colour".
Special Characters
Control the regex engine.
Escape
\ escapes a special character to use it as a literal.
Example: \. matches "." instead of any character.
Any Character
. matches any character except newline.
Example: a.c matches "abc", "a7c", etc.
Groups and Ranges
Specify groups of expressions and character ranges.
Capture Group
( ) captures the matched group.
Example: (abc)+ captures repetitions of "abc".
Character Range
[ ] matches any character in the set.
Example: [a-z] matches any lowercase letter.
Assertions
Provide lookahead and lookbehind assertions.
Positive Lookahead
(?= ) ensures subpattern matches.
Example: a(?=b) matches "a" only if "b" follows.
Negative Lookahead
(?! ) ensures subpattern does not match.
Example: a(?!b) matches "a" only if "b" doesn't follow.
Pattern Modifiers
Alter regex behavior.
Case Insensitive
i performs case-insensitive matching.
Example: /abc/i matches "ABC", "abc", etc.
Global
g matches multiple occurrences.
Example: /hello/g matches all "hello" in string.
String Replacement
Change parts of the string using regex.
Replace Function
replace() changes matched text with new string.
Example: "abc".replace(/b/, "d") results in "adc".
Substitution
$ references capture groups.
Example: replace(/(\w)\1/, "$1") shortens doubled letters.
Escape Sequences
Escape characters in regex.
Newline
\n matches a newline character.
Example: Matches "\n" in a multiline string.
Tab
\t matches a tab character.
Example: Matches 8-space tab sequences.
Common Metacharacters
Define regex behavior.
Alternation
| acts like Boolean OR.
Example: cat|dog finds "cat" or "dog".
Start of Word
\b matches word boundary.
Example: \bword\b matches "word" as a whole word.
POSIX
Standardized set of character classes.
Alphanumeric
[:alnum:] matches any letter or digit.
Example: [[:alnum:]] matches "a", "1", etc.
Blank
[:blank:] matches spaces and tabs.
Example: Extracts spaces in "Hello World".
Regular Expression Full Cheatsheet Mind Map