Regular Expression Cheat Sheet
Last updated on 2023-05-03 | Edit this page
Regular Expression Cheat Sheet
-
[]defines a range of characters. -
.matches any character. -
\is used to escape the following character when that character is a special character. So, for example, a regular expression that found ‘.com’ would be\\.combecause.is a special character that matches any character. -
\dmatches any single digit. -
\wmatches any part of word character (equivalent to[A-Za-z0-9]). -
\smatches any space, tab, or newline. -
^asserts the position at the start of the line. So what you put after it will only match if they are the first characters of a line. -
$asserts the position at the end of the line. So what you put before it will only match if they are the last characters of a line. -
\badds a word boundary. Putting this either side of a word stops the regular expression matching longer variants of words. -
*matches the preceding element zero or more times. For example,ab*cmatches ‘ac’, ‘abc’, ‘abbbc’, etc. -
+matches the preceding element one or more times. For example,ab+cmatches ‘abc’, ‘abbbc’ but not ‘ac’. -
?matches when the preceding character appears zero or one time. -
{VALUE}matches the preceding character the number of times define by VALUE; ranges can be specified with the syntax{VALUE,VALUE}. -
|means or.