Regular Expressions

Regular expressions are a useful tool for pattern matching. They can be used for simple patterns but are expandable to create extremely complex patterns.

symbol function example
. any character except newline
\ escape character \. matches .
^ at start of string ^Start
$ at end of string end$
\d any digit [0-9]
\D any non-digit
\w any word character (i.e. a letter) [A-Za-z]
\W any non-word character
\s any whitespace space, tab, etc.
\S any non-whitespace
\t matches tab
\b word boundary
[] user-defined character set [abc], [a-z], [1-5]
[^] excluded character set [^abc] = anything but a, b, or c
| or a|b = a or b
? zero or one of the preceding element a?
* zero or more of the preceding element [a-e]*
+ one or more of the preceding element \d+
{n} exactly n of the preceding element
{n,} n or more
{n,m} between n and m
(<expr>) capture group remembers the matching sequence
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License