Regular Expression Tutorial

Practice

pattern attribute Type your text Check
a
abc
1
123
\d
\D
.
\.
[abc]
[^abc]
[a-z]
[a-zA-Z]
[0-9]
[a-zA-Z0-9]
\w
\W
\d{3}
\w{3}
\d{3,5}
\d{3,}
o*
o+
o?
do*g
do+g
do?g
\s
\S
\s+
\S+
^d
g$
^d.*g$
(dog|cat)

Excercises

pattern attribute Target String Check
\d{2,3}-?\d{3,4}-?\d{4}
\w+\.?\w+\+?\w+@\w+\.?\w+\.?\w+

Lesson Note

Pattern Description
abc… Letters
123… Digits
\d Any Digit
\D Any Non-digit character
. Any Character
\. Dot
[abc] Only a, b, or c
[^abc] Not a, b, nor c
[a-z] Characters a to z
[a-zA-Z] Characters a to z or A to Z
[0-9] Numbers 0 to 9
[a-zA-Z0-9] Characters a to z or A to Z or 0 to 9
\w Any Alphanumeric character
\W Any Non-alphanumeric character
{m} m Repetitions
{m,n} m to n Repetitions
{m,} m or more Repetitions
* Zero or more repetitions
+ One or more repetitions
? Optional character
\s Any Whitespace
\S Any Non-whitespace character
^…$ Starts and ends
(…) Capture Group
(a(bc)) Capture Sub-group
(.*) Capture all
(abc|def) Matches abc or def