Regex Pattern Matching

Prakhar S
2 min readFeb 11, 2022

--

Photo by Vojtech Bruzek on Unsplash

Some of the most common metacharacters used in Regex along with usage:

.

matches any character including whitespace.

+

matches 1 or more occurrences of the preceding subexpression.

?

matches 0 or 1 occurrence of the preceding subexpression.

*

matches 0 or more occurrences of the preceding subexpression.

\d

matches any digit character.

\w

matches any alphanumeric character [A-Z][a-z][0–9]. Not case sensitive.

{m}

Matches exactly m occurrences of the preceding subexpression.

{m,}

Matches at least m occurrences of the preceding subexpression.

{m,n}

Matches at least m, but not more than n occurrences of the preceding subexpression.

[….]

Matches any character inside the brackets.

[^….]

Matches any character not in the brackets.

(….)

Matches the expression inside the brackets exactly.

|

Matches either preceding or succeeding.

^

Matches the subsequent expression only when it occurs at the beginning of the string.

$

Matches the preceding expression only when it occurs at the end of the string.

--

--