Regular Expression Testing Tool Introduction

The Regular Expression Testing Tool provides JavaScript regex validation, regular expression validation, regex checking, and regex testing tools. It allows for custom regular expression extraction of text content, validation of any regex, extraction of URLs, online regex formatting, and more to help users.


Purpose of Regular Expressions

A Regular Expression (regex) is a text pattern that includes ordinary characters (like letters from a to z) and special characters (called "metacharacters"). A regular expression uses a single string to describe or match a series of strings that follow a specific syntax rule. Although regular expressions can be complicated, they are powerful. Learning to use them will increase your efficiency and give you a sense of accomplishment, as many programming languages support regex for string manipulation.

Common Metacharacters
CodeDescription
.Matches any character except newline
\wMatches letters, digits, or underscores
\sMatches any whitespace character
\dMatches digits
\bMatches the start or end of a word
^Matches the start of a string
$Matches the end of a string
Common Quantifiers
Code/SyntaxDescription
*Matches zero or more occurrences
+Matches one or more occurrences
?Matches zero or one occurrence
{n}Matches exactly n occurrences
{n,}Matches n or more occurrences
{n,m}Matches between n and m occurrences
Common Negations
Code/SyntaxDescription
\WMatches any character that is not a letter, digit, underscore, or Chinese character
\SMatches any character that is not a whitespace
\DMatches any character that is not a digit
\BMatches any position that is not the start or end of a word
[^x]Matches any character except x
[^aeiou]Matches any character except aeiou

Comprehensive Regular Expression Reference

CharacterDescription
^\d+$//Matches non-negative integers (positive integers + 0)
//Matches integers ^\d+(\.\d+)?$//Matches non-negative floating-point numbers (positive floating-point numbers + 0)
^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$//Matches positive floating-point numbers
^((-\d+(\.\d+)?)|(0+(\.0+)?))$//Matches non-positive floating-point numbers (negative floating-point numbers + 0)
^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$//Matches negative floating-point numbers
^(-?\d+)(\.\d+)?$//Matches floating-point numbers
^[A-Za-z]+$//Matches strings composed of 26 English letters
^[A-Z]+$//Matches strings composed of 26 uppercase English letters
^[a-z]+$//Matches strings composed of 26 lowercase English letters
^[A-Za-z0-9]+$//Matches strings composed of numbers and 26 English letters
^\w+$//Matches strings composed of numbers, 26 English letters, or underscores
^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$//Matches email addresses
^[a-zA-z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$//Matches URLs
[\u4e00-\u9fa5]//Matches Chinese characters
[^\x00-\xff]//Matches double-byte characters (including Chinese characters)
\n[\s| ]*\r//Matches blank lines
/<(.*)>.*<\/>|<(.*)\/>///Matches HTML tags
(^\s*)|(\s*$)//Matches leading and trailing spaces
\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*//Matches email addresses
^[a-zA-z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$//Matches URLs
^[a-zA-Z][a-zA-Z0-9_]{4,15}$//Matches valid account names (letters at the beginning, 5-16 bytes, allows letters, numbers, underscores)
(\d{3}-|\d{4}-)?(\d{8}|\d{7})?//Matches domestic telephone numbers
^[1-9]*[1-9][0-9]*$//Matches QQ numbers
Your Footprints: