Regex tester introduction

The regular expression test tool provides js regular expression validation, regex verification and regex testing. You can use a custom regular expression online to extract text, validate any regular expression, extract URLs with a regex and format regex online. We hope it is helpful to everyone.


What regular expressions do

A regular expression (Regular Expression) is a text pattern that includes ordinary characters (for example the letters between a and z) and special characters (called "metacharacters"). A regular expression uses a single string to describe and match a series of strings that follow a syntactic rule. Regular expressions are tedious but powerful; mastering them not only improves efficiency but gives you an absolute sense of achievement. Many programming languages support string operations with regular expressions.

Common metacharacters
CodeDescription
.Matches any character except a newline
\wMatches letters, digits or underscores
\sMatch any whitespace
\dMatch digits
\bMatch the start or end of a word
^Match start of string
$Match end of string
Common quantifiers
Code/SyntaxDescription
*Repeat zero or more
+Repeat once or more
?Repeat zero or one time
{n}Repeat n times
{n,}Repeat n or more
{n,m}Repeat n to m times
Common antonyms
Code/SyntaxDescription
\WMatch any character that is not a letter, digit, underscore or Chinese character
\SMatches any non-whitespace character
\DMatches any non-digit character
\BMatch a position that is not a word start or end
[^x]Matches any character except x
[^aeiou]Match any character except the letters aeiou

Regular expression complete reference

CharacterDescription
^\d+$//Matches a non-negative integer (positive integer + 0)
// Match an integer ^\d+(\.\d+)?$//Match non-negative floats (positive floats + 0)
^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$// Match positive floating-point numbers
^((-\d+(\.\d+)?)|(0+(\.0+)?))$//Match non-positive floats (negative floats + 0)
^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$// Match negative floating-point numbers
^(-?\d+)(\.\d+)?$// match floating-point numbers
^[A-Za-z]+$?????????//Matches a string made up of the 26 English letters
^[A-Z]+$ ???//Match a string composed of the 26 uppercase English letters
^[a-z]+$//Match a string composed of the 26 lowercase English letters
^[A-Za-z0-9]+$//Match a string composed of digits and the 26 English letters
^\w+$//Match a string composed of digits, the 26 English letters or underscores
^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$// Match email address
^[a-zA-z]+://match (\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$// match url
[\u4e00-\u9fa5]Regex for matching Chinese characters
[^\x00-\xff]Matches double-byte characters (including Han characters)
\n[\s| ]*\rRegex matching empty lines
/<(.*)>.*<\/>|<(.*)\/>/Regex for matching HTML tags
(^\s*)|(\s*$)Regex matching leading and trailing whitespace
\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*Regular expression that matches Email addresses
^[a-zA-z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$Regex for matching URLs
^[a-zA-Z][a-zA-Z0-9_]{4,15}$Check whether an account name is valid (starts with a letter, 5-16 bytes, letters, digits and underscores allowed)
(\d{3}-|\d{4}-)?(\d{8}|\d{7})?Match domestic phone numbers
^[1-9]*[1-9][0-9]*$Match Tencent QQ numbers
Recently used:

How to use

This tool belongs to the “Code & markup formatting” category.

  1. 1Paste your source and open the matching formatter — HTML, CSS, JS, SQL, PHP and more each have their own page.
  2. 2Format first to read the structure and catch syntax errors, then minify for the version you ship.
  3. 3Need it as a string literal? Use the HTML-to-JS/PHP/C# converters, which escape quotes and line breaks for you.

Your input is processed locally in the browser whenever possible. We do not store it.

Frequently asked questions

What is the difference between format and minify?

Formatting expands code into indented lines for readability; minifying strips whitespace and comments to reduce size.

Will it change what my code does?

Only whitespace, line breaks and comments are touched. With JavaScript that relies on automatic semicolon insertion, test the minified output before shipping.

Is my code uploaded?

Formatting and minifying run client-side. Nothing is written to server logs.