Regex cheatsheet

Regular expression is a powerful but difficult tool to define search patterns. Here are some tips and tricks.

Regex Usage / explanation
+ the + means at least one
* the * means none or more
. the dot matches a single character, without caring what that character is, The only exception are line break characters. In general the dot does not match line breaks by default.
.* the dot matches any character, and the star allows the dot to be repeated any number of times
double quotes are used to generate boundaries in a search pattern “abc” would query for abc exactly
range, for example [a-z] which means any lowercase character from a to z
\ escape the next character
“\”.*\”” when searching for a double quote inside a string (surrounded by double quotes) you need to delimit/escape the outer double quotes
[] two square brackets mean: match one item in this list, for example [abc] means any character a,b or c, you could also use [a-c]
“[^”\r\n]*” find all matches between the quotes except (^) for double quotes (“) and line feeds (\r\n)
\n this iss a line break
\r this is a line break character
\r\n scripting languages read and write files in text mode by default. When running on Windows, \r\n pairs are automatically converted into \n when a file is read
\r this is a line break character
\u2028 javaScript unicode line separator
\u2029 javaScript unicode page separator
\d\d[- /.]\d\d[- /.]\d\d regex allows a dash, space, dot and forward slash as date separators


So, what do you think ?