Regular Expression

From Ideasplace
Jump to navigation Jump to search

Basic RegEx Cheat Sheet

Symbol Name Meaning Example Matches
Literals
(text) Literal Matches exact text cat "cat"
Wildcards & Classes
. Dot Matches any single character h.t "hat", "hot"
[ ] Brackets List of allowed characters b[ai]t "bat", "bit"
[^ ] Negation Matches anything NOT in the list [^a] Any char except 'a'
Quantifiers
* Star 0 or more times go*d "gd", "god", "good"
+ Plus 1 or more times go+d "god", "good"
? Question 0 or 1 time (Optional) colou?r "color", "colour"
Anchors
^ Caret Start of string ^The "The end"
$ Dollar End of string end$ "The end"
Special Characters
\ Escape Treats special characters as text \. "." (actual dot)
\ Escape Treats special characters as text \$ "$" (actual dollar)
\d Digit Any number 0-9 \d\d "42", "99"
\w Word Letter, number, or underscore \w+ "Hello_1"
\s Space Whitespace (space, tab, enter) A\sB "A B"