regexp Regular Expression

Regular Expression

regrex package

On-line Regular Expression

Meta Characters

Metacharacters are characters that are interpreted in a special way by a RegEx engine. Here’s a list of metacharacters:

[] . ^ $ * + ? {} () \ |

[] – Square brackets

Square brackets specifies a set of characters you wish to match.

. – Period

A period matches any single character (except newline '\n').

 – Caret

The caret symbol ^ is used to check if a string starts with a certain character.

$ – Dollar

The dollar symbol $ is used to check if a string ends with a certain character.

* – Star

The star symbol * matches zero or more occurrences of the pattern left to it.

+ – Plus

The plus symbol + matches one or more occurrences of the pattern left to it.

? – Question Mark

The question mark symbol ? matches zero or one occurrence of the pattern left to it.

{} – Braces

Consider this code: {n,m}. This means at least n, and at most m repetitions of the pattern left to it.

| – Alternation

Vertical bar | is used for alternation (or operator).

() – Group

Parentheses () is used to group sub-patterns.

\ – Backslash

Backlash \ is used to escape various characters including all metacharacters.

Special Sequences

Special sequences make commonly used patterns easier to write.