Regular Expressions (Regex/RegExp)
Patterns of text that specifies a search pattern in text.
Online Tools
-
You’re able to try various patterns in this site easily.
-
Learn, build, and test regex.
Commands
Grep Pattern Matching
Example Patterns
Below is the basic examples.
[a-z]
# a, b, c, ..., y, z
[a-z]+
# abc, aaabbbcc, ghslkdja, ...
[a-zA-Z]
# a, A, b, B, ..., z, Z
[a-z]zz
# azz, bzz, czz, ...
[a-zA-Z]+zz
# azz, AaBbCdefzz, hkIkWEzz, ...
[a-z]?zz
# zz, azz, bzz, ...
[0-9]
# 0, 1, 2, ..., 9
[0-9]+
# 0, 00, 123, 77777, ...
[^a]pple
# bpple, cpple, zpple, 2pple, ...
[^a-c]pple
# dpple, epple, 2pple, ...
a.c
# aac, abc, a"c, a;c, a c, ...
a\.c
# a.c
abc?
# abc, ab
\d
# 0, 1, ..., 9
\D
# a, b, A, Z, ;, +, ?, ....
\w
# a, A, b, B, ..., z, Z, 0, 1, 3, ...9
\W
# !, ", #, ...
\s
# \r, \n
\S
# a, A, b, B, ..., 0, 1, ..., !, ", #, ...
a{3}
# aaa
abc{3}
# abccc
\d{3}
# 123, 444, 987, ...
a{2,5}
# aa, aaa, aaaa, aaaaa
a{3,}
# aaa, aaaa, aaaaa, aaaaaa, ...
a*
# <NONE>, a, aa, aaa, aaaa, ...
a+
# a, aa, aaa, aaaa, ...
^abc
# start with "abc"
xyz$
# end with "xyz"
EOF\$$
# end with "EOF$"
hello (john|jane)
# hello john, hello jane
(abc){3}
# abcabcabc