FAQ

Frequently Asked Questions

General Regular Expression Patterns with explanation

  Username Regular Expression

^[a-z0-9_-]{3,15}$

Description

^
# Start of the line
[a-z0-9_-]
# Match characters and symbols in the list, a-z, 0-9, underscore, hyphen
{3,15}
# Length at least 3 characters and maximum length of 15
$
# End of the line

  Password Regular Expression

((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})

Description

(
# Start of group
(?=.*\d)
# Must contains one digit from 0-9
(?=.*[a-z])
# Must contains one lowercase characters
(?=.*[A-Z])
# Must contains one uppercase characters
(?=.*[@#$%])
# Must contains one special symbols in the list “@#$%”
.
# Match anything with previous condition checking
{6,20}
# Length at least 6 characters and maximum of 20
)
# End of group

  Email Address Regular Expression

^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*
@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$

Description

^
# Start of the line
[_A-Za-z0-9-\\+]+
# Must start with string in the bracket [ ], must contains one or more (+)
(
# Start of group #1
\\.[_A-Za-z0-9-]+
# Follow by a dot “.” and string in the bracket [ ], must contains one or more (+)
)*
# End of group #1, this group is optional (*)
@
# Must contains a “@” symbol
[A-Za-z0-9-]+
# Follow by string in the bracket [ ], must contains one or more (+)
(
# Start of group #2 – first level TLD checking
\\.[A-Za-z0-9]+
# Follow by a dot “.” and string in the bracket [ ], must contains one or more (+)
)*
# End of group #2, this group is optional (*)
(
# Start of group #3 – second level TLD checking
\\.[A-Za-z]{2,}
# Follow by a dot “.” and string in the bracket [ ], with minimum length of 2
)
# End of group #3
$
# End of the line

  IP Address Regular Expression

^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.
([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$

Description

^
# Start of the line
(
# Start of group #1
[01]?\\d\\d?
# Can be one or two digits. If three digits appear, it must start either 0 or 1
# e.g ([0-9], [0-9][0-9],[0-1][0-9][0-9])
|
# …or
2[0-4]\\d
# Start with 2, follow by 0-4 and end with any digit (2[0-4][0-9])
|
# …or
25[0-5]
# Start with 2, follow by 5 and ends with 0-5 (25[0-5])
)
# End of group #1
\.
# Follow by a dot “.”
….
# Repeat 3 times (3x)
$
# End of the line

  Hexadecimal Color Code Regular Expression

^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$

Description

^
# Start of the line
#
# Must constains a “#” symbol
(
# Start of group #1
[A-Fa-f0-9]{6}
# Any strings in the list, with length of 6
|
# ..or
[A-Fa-f0-9]{3}
# Any strings in the list, with length of 3
)
# End of group #1
$
# End of the line

  Image File Extension Regular Expression

([^\s]+(\.(?i)(jpg|png|gif|bmp))$)

Description

(
# Start of the group #1
[^\s]+
# Must contains one or more anything (except white space)
(
# Start of the group #2
\.
# Follow by a dot “.”
(?i)
# Ignore the case sensive checking for the following characters
(
# Start of the group #3
jpg
# Contains characters “jpg”
|
# …or
png
# Contains characters “png”
|
# …or
gif
# Contains characters “gif”
|
# …or
bmp
# Contains characters “bmp”
)
# End of the group #3
)
# End of the group #2
$
# End of the line
)
# End of the group #1

  Time in 12-Hour Format Regular Expression

(1[012]|[1-9]):[0-5][0-9](\\s)?(?i)(am|pm)

Description

(
# Start of the group #1
1[012]
# Start with 10, 11, 12
|
# …or
[1-9]
# Start with 1,2,…9
)
# End of the group #1
:
# Follow by a semi colon (:)
[0-5][0-9]
# Follow by 0..5 and 0..9, which means 00 to 59
(\\s)?
# Follow by a white space (optional)
(?i)
# Next checking is case insensitive
(am|pm)
# Follow by am or pm

  Time in 24-Hour Format Regular Expression

([01]?[0-9]|2[0-3]):[0-5][0-9]

Description

(
# Start of the group #1
[01]?[0-9]
# Start with 0-9,1-9,00-09,10-19
|
# …or
2[0-3]
# Start with 20-23
)
# End of the group #1
:
# Follow by a semi colon (:)
[0-5][0-9]
# Follow by 0..5 and 0..9, which means 00 to 59

  Date Format (dd/mm/yyyy) Regular Expression

(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)

Description

(
# Start of the group #1
0?[1-9]
# 01-09 or 1-9
|
# …or
[12][0-9]
# 10-19 or 20-29
|
# …or
3[01]
# 30, 31
)
# End of the group #1
/
# Follow by a “/”
(
# Start of the group #2
0?[1-9]
# 01-09 or 1-9
|
# …or
1[012]
# 10,11,12
)
# End of the group #2
/
# Follow by a “/”
(
# Start of the group #3
(19|20)\\d\\d
# 19[0-9][0-9] or 20[0-9][0-9]
)
# End of the group #3

Video tutorials