Regex TesterNEW
Test regular expressions live with highlighted matches and groups
Checking your access…
AllFreeTool's Regular Expression Tester debugs regex patterns online for free: enter a pattern and flags and matches update within 300 milliseconds, every hit is highlighted, and each result lists the full match, capture groups, and position index, together with a live replacement preview using $1 and $& references. It is a handy tool for developers and operations staff.
Built-in templates cover phone numbers, email addresses, 18-digit ID card numbers, URLs, IPv4, Chinese text, postal codes, and strong passwords; one click fills in the pattern and sample text so you can modify and learn from them. All matching runs in your browser, test text is never uploaded to the server, and even sensitive logs can be pasted safely.
Why use Regex Tester on AllFreeTool?
Live Highlighting
Matching starts as you type with a 300ms debounce; hit fragments are highlighted in yellow and the match count is always visible.
Ready-Made Templates
Eight built-in templates: phone number, email, ID card, URL, IPv4, Chinese text, postcode, and strong password.
Capture Group Details
Every match shows its ordinal, the full match, the index position, and the contents of group1..n.
Live Replacement
Use $1 and $2 to reference capture groups and $& for the whole match, with a live preview you can copy.
How to use Regex Tester
Enter Your Pattern
Type the pattern between /.../ and enable the g, i, m, s, u, or y flags as needed, or click a ready-made template.
Paste Test Text
Paste the text you want to match into the test area; the match results and highlight preview refresh in real time.
Review Details And Replace
Check the position and capture groups of every hit, then type a replacement string to preview and copy the result.
Common questions
What does the g flag mean in a regex?+
g stands for global. Without it only the first match is found and replaced; with it, every match in the text is processed. You need g for counting occurrences or replacing everything, and can skip it when you only want to check the beginning. Other common flags: i ignores case, m lets ^ and $ match each line, and s lets . match line breaks.
What do $1 and $& mean during replacement?+
$1 and $2 stand for the content captured by the first and second parenthesized groups in the pattern, while $& stands for the whole match itself. For example, matching a date with (\d{4})-(\d{2})-(\d{2}) and replacing it with $1/$2/$3 turns 2024-03-15 into 2024/03/15. The replacement area of this tool follows exactly these native semantics.
How do I write a regex for phone numbers and ID cards?+
Mainland China mobile numbers commonly use ^1[3-9]\d{9}$, and 18-digit ID card numbers commonly use [1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]. Just click the matching template in the tool to fill it in, then verify the result against the sample text.
Why does my ^...$ regex fail on multi-line text?+
By default, ^ and $ only match the very beginning and the very end of the whole text. To make them match the start and end of every line, add the m (multiline) flag. The phone number and strong password templates in this tool already carry g and m, so you can use them as a reference.