Snippet: Regex Characters Cheat Sheet

Additionally, you'll find one of the greatest explanations of regex here: http://automatetheboringstuff.com/chapter7/
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
  1. . Any character except newline.
  2. \. A period (and so on for \*, \(, \\, etc.)
  3. ^ The start of the string.
  4. $ The end of the string.
  5. \d,\w,\s A digit, word character [A-Za-z0-9_], or whitespace.
  6. \D,\W,\S Anything except a digit, word character, or whitespace.
  7. [abc] Character a, b, or c.
  8. [a-z] a through z.
  9. [^abc] Any character except a, b, or c.
  10. aa|bb Either aa or bb.
  11. ? Zero or one of the preceding element.
  12. * Zero or more of the preceding element.
  13. + One or more of the preceding element.
  14. {n} Exactly n of the preceding element.
  15. {n,} n or more of the preceding element.
  16. {m,n} Between m and n of the preceding element.
  17. ??,*?,+?,
  18. {n}?, etc. Same as above, but as few as possible.
  19. (expr) Capture expr for use with \1, etc.
  20. (?:expr) Non-capturing group.
  21. (?=expr) Followed by expr.
  22. (?!expr) Not followed by expr.