Regex Tester

Regex Tester

~r/
/

For example: \A[a-z0-9-]+\z

U f i m s u x

Function

Which Regex function to run

Result

result = ""

Visualization


          
[abc]
A single character of: a, b, or c
[^abc]
Any single character except: a, b, or c
[a-z]
Any single character in the range a-z
[a-zA-Z]
Any single character in the range a-z or A-Z
^
Start of line
$
End of line
\A
Start of string
\z
End of string
.
Any single character
\s
Any whitespace character
\S
Any non-whitespace character
\d
Any digit
\D
Any non-digit
\w
Any word character (letter, number, underscore)
\W
Any non-word character
\b
Any word boundary
(...)
Capture everything enclosed
(a|b)
a or b
a?
Zero or one of a
a*
Zero or more of a
a+
One or more of a
a{3}
Exactly 3 of a
a{3,}
3 or more of a
a{3,6}
Between 3 and 6 of a
unicode (u)
enables Unicode specific patterns like \p and change modifiers like \w, \W, \s and friends to also match on Unicode. It expects valid Unicode strings to be given on match
caseless (i)
adds case insensitivity
dotall (s)
causes dot to match newlines and also set newline to anycrlf; the new line setting can be overridden by setting (*CR) or (*LF) or (*CRLF) or (*ANY) according to :re documentation
multiline (m)
causes ^ and $ to mark the beginning and end of each line; use \A and \z to match the end or beginning of the string
extended (x)
whitespace characters are ignored except when escaped and allow # to delimit comments
firstline (f)
forces the unanchored pattern to match before or at the first newline, though the matched text may continue over the newline
ungreedy (U)
inverts the "greediness" of the regexp (the previous r option is deprecated in favor of U)
US Phone Number
\(?\d{3}\)?-? *\d{3}-? *-?\d{4}
Unix Epoch Time (named captures)
\A(?<sign>-)?(?<seconds>\d{10,11})(?:\.(?<subseconds>\d{1,10}))?\z
Entire string is only numbers
\A[0-9]*\z
HTML attribute (eg: class)
(?<=class=(?:'|")).*?(?=(?:'|").*?>)
Simple Email Address
\A[^\s]+@[^\s]+\z
Only alpha-numeric, underscore, and dash characters
\A[\w-]+\z