Regular expressions pcre2 cheatsheet

Regular expressions pcre2: Characters and anchors

9 common Regular expressions pcre2 tasks.

Match digits

Match one or more digits. Use \D for anything that is not a digit.

\d+

Match word characters

Match letters, digits and underscore. Use \W for the opposite.

\w+

Match whitespace

Match spaces, tabs and line breaks. Use \S for the opposite.

\s+

Match any character

Match any single character except a line break, unless the dotall flag is set.

.

Match one of several characters

Match a single letter, either case.

[A-Za-z]

Match anything except some characters

Match one character that is not a digit.

[^0-9]

Match the whole line

Anchor to the start and end of the text. This matches a phone number like 555-1234.

^\d{3}-\d{4}$

Match a whole word

Match cat but not category or concat.

\bcat\b

Match a special character literally

Escape characters such as . * + ? ( ) [ ] { } | \ ^ $ with a backslash.

3\.14

Was this page helpful?