RegEx Tester

Regular expressions (regex or regexp) are very effective for extracting information from text. To do this, you need to search for one or more matches by a specific pattern (i.e., a specific sequence of ASCII or unicode characters). The applications of regex are diverse, from validation to parsing / replacing strings, transferring data to other formats and web scraping.
Just enter the regular expression below and some text to test your regular expression, or scroll down to try one of our examples.

/\g

Flags





Results


Matches

Examples to Try

Try some of the examples below to get a feel about how this RegEx Tester works. Just click on the button below for for the examples to appear in the input fields above. Play around with the regular expressions and you'll soon see what is happening.

Type Description Expression Try
Date Matches the date format YYYY-mm-dd H:i:s (MySQL Date) \d\d\d\d-(0?[1-9]|1[0-2])-(0?[1-9]|[12][0-9]|3[01]) (00|[0-9]|1[0-9]|2[0-3]):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9])+
Date 2 Will match dates with dashes, slashes or with spaces (e.g. dd-mm-yyyy dd/mm/yyyy dd mm yyyy), and optional time separated by a space or a dash (e.g. dd-mm-yyyy-hh:mm:ss or dd/mm/yyyy hh:mm:ss). (0?[1-9]|[12][0-9]|3[01])([ \/\-])(0?[1-9]|1[012])\2([0-9][0-9][0-9][0-9])(([ -])([0-1]?[0-9]|2[0-3]):[0-5]?[0-9]:[0-5]?[0-9])?
String Simple example matching words in text [a-zA-Z]+
URL Matches the elements of a URL, including the protocol, subdomain, domain, path, filename, query parameters, and anchor. ((https?|ftp):\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9]\.[^\s]{2,})
IP v4 Matches the elements of an IP address(IPv4). (?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
IP v6 Matches the elements of an IP address(IPv6). (([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))
Color Matches the elements of a hexadecimal color code (#FFFFFF). The color code can take either the 6 or 3 hexadecimal digits format. Add ? after the # to make this optional. #(([0-9a-fA-F]{2}){3}|([0-9a-fA-F]){3})
Email Matches an Email address. [a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*
CSS Comments Match standard CSS comments. \/\*[^*]*\*+([^\/*][^*]*\*+)*\/

About Regular Expressions

Learn more about Regex by using the cheat sheet below, with explanations for each character that is used in regular expressions.

Special Characters
^Matches the expression to its right at the start of a string. It matches every such instance before each \n in the string.
$Matches the expression to its left at the end of a string. It matches every such instance before each \n in the string.
.Matches any character except line terminators like \n.
\Escapes special characters or denotes character classes.
A|BMatches expression A or B. If A is matched first, B is left untried.
+Greedily matches the expression to its left 1 or more times.
*Greedily matches the expression to its left 0 or more times.
?Greedily matches the expression to its left 0 or 1 times. But if ? is added to qualifiers (+, *, and ? itself) it will perform matches in a non-greedy manner.
{m}Matches the expression to its left m times, and not less.
{m,n}Matches the expression to its left m to n times, and not less.
{m,n}?Matches the expression to its left m times, and ignores n. See ? above.
Character Classes (Special Sequences)
\wMatches alphanumeric characters, which means a-z, A-Z, and 0-9. It also matches the underscore, _.
\dMatches digits, which means 0-9.
\DMatches any non-digits.
\sMatches whitespace characters, which include the \t, \n, \r, and space characters.
\SMatches non-whitespace characters.
\bMatches the boundary (or empty string) at the start and end of a word, that is, between \w and \W.
\BMatches where \b does not, that is, the boundary of \w characters.
\AMatches the expression to its right at the absolute start of a string whether in single or multi-line mode.
\ZMatches the expression to its left at the absolute end of a string whether in single or multi-line mode.
Sets
[ ]Contains a set of characters to match.
[abc]Matches either a, b, or c. It does not match abc.
[a-z]Matches any alphabet from a to z.
[a\-z]Matches a, -, or z. It matches - because \ escapes it.
[a-]Matches a or -, because - is not being used to indicate a series of characters.
[-a]As above, matches a or -.
[a-z0-9]Matches characters from a to z and also from 0 to 9.
[(+*)]Special characters become literal inside a set, so this matches (, +, *, and ).
[^ab5]Adding ^ excludes any character in the set. Here, it matches characters that are not a, b, or 5.
Groups
( )Matches the expression inside the parentheses and groups it.
(? )Inside parentheses like this, ? acts as an extension notation. Its meaning depends on the character immediately to its right.
(?PAB)Matches the expression AB, and it can be accessed with the group name.
(?aiLmsux)Here, a, i, L, m, s, u, and x are flags:
  • a — Matches ASCII only
  • i — Ignore case
  • L — Locale dependent
  • m — Multi-line
  • s — Matches all
  • u — Matches unicode
  • x — Verbose
(?:A)Matches the expression as represented by A, but unlike (?PAB), it cannot be retrieved afterwards.
(?#...)A comment. Contents are for us to read, not for matching.
A(?=B)Lookahead assertion. This matches the expression A only if it is followed by B.
A(?!B)Negative lookahead assertion. This matches the expression A only if it is not followed by B.
(?<=B)APositive lookbehind assertion. This matches the expression A only if B is immediately to its left. This can only matched fixed length expressions.
(?<!B)ANegative lookbehind assertion. This matches the expression A only if B is not immediately to its left. This can only matched fixed length expressions.
(?P=name)Matches the expression matched by an earlier group named “name”.
(...)\1The number 1 corresponds to the first group to be matched. If we want to match more instances of the same expresion, simply use its number instead of writing out the whole expression again. We can use from 1 up to 99 such groups and their corresponding numbers.