Regex Tester

Test and debug regular expressions with real-time matching

//g

Enter test string to see matches

Common Patterns

Email

Basic email validation

/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g

Phone

International phone numbers

/\+?\d{1,4}?[-\s]?\(?\d{1,3}\)?[-\s]?\d{1,4}[-\s]?\d{1,9}/g

URL

HTTP/HTTPS URLs

/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g

IPv4

IPv4 addresses

/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/g

Date

YYYY-MM-DD format

/\d{4}-\d{2}-\d{2}/g

Hex Color

Hex color codes

/#[a-fA-F0-9]{6}|#[a-fA-F0-9]{3}/g

Quick Reference

Character Classes

\d - Digits (0-9)
\w - Word characters
\s - Whitespace
. - Any character

Quantifiers

* - Zero or more
+ - One or more
? - Zero or one
{n,m} - Between n and m

Anchors

^ - Start of string
$ - End of string
\b - Word boundary
\B - Non-word boundary

Complete Regular Expression Tester Guide

Regular Expression Tester is an essential text processing tool for developers. Supports real-time testing of regex patterns, highlights matching results, views capture groups, provides common pattern examples and quick reference. Whether validating form input, extracting data, search and replace, or learning regex, you can easily accomplish it. The tool is completely free, supports all JavaScript regex features, including global matching, case insensitive, multiline mode, etc. Understanding how to use the regex tester helps you quickly write and debug regular expressions, improve text processing efficiency, and avoid common errors.

1
如何使用 / How to Use

Step 1: Enter Regex Pattern

Enter your regular expression in the "Regular Expression Pattern" input box. No need to add slashes and flags (like /pattern/g), just enter the pattern itself. For example, enter \d+ to match one or more digits. The tool validates syntax in real-time and prompts immediately if there are errors.

Step 2: Select Flags

Select regex flags as needed: g (global match, find all matches), i (case insensitive), m (multiline mode, ^ and $ match line start/end), s (dot matches newlines), u (Unicode support), y (sticky match). You can select multiple flags simultaneously.

Step 3: Enter Test String

Enter the text to test in the "Test String" text box. Can be single-line or multi-line text. The tool displays matching results in real-time, matched parts are highlighted in yellow. Supports large text testing, you can paste logs, code, or any text content.

Step 4: View Match Results

The right side displays all matching results, including match count, highlighted text, detailed information for each match (matched content, position, capture groups). You can copy all match results with one click. If capture groups (parentheses) are used, the content of each group is displayed.

Step 5: Use Common Patterns

The bottom of the page provides common regex pattern examples, including email, phone, URL, IP address, date, color code, etc. Click "Use" button to quickly load examples for learning and reference. There is also a quick reference table listing common syntax like character classes, quantifiers, anchors, etc.

2
实际应用场景 / Use Cases

1Form Validation

In web development, you often need to validate if user input format is correct. Using regex can validate email, phone, ID card, zip code, URL, etc. Test regex in the tester first, ensure it correctly matches valid input and rejects invalid input, then apply to code. Avoid using untested regex in production.

2Data Extraction

Extract data in specific formats from text, such as extracting IP addresses, timestamps, error codes from logs, extracting links, emails, phone numbers from web pages, extracting function names, variable names from code. Using capture groups can extract different parts of data. The tester helps you quickly verify if extraction logic is correct.

3Search and Replace

When performing batch search and replace in text editors, IDEs, or code, regex is very powerful. Can search complex patterns, use capture groups for smart replacement. For example, swap date formats (MM/DD/YYYY → YYYY-MM-DD), rename variables, format code. Verify search pattern in tester first to avoid mistakes.

4Log Analysis

When analyzing server logs and application logs, you need to extract key information from large amounts of text. Using regex can match specific log formats, extract time, level, message, IP, user, etc. The tester helps you quickly write and debug log parsing rules, improving log analysis efficiency.

5Text Cleaning

When processing scraped data, user input, or imported files, you often need to clean text: remove extra spaces, unify line breaks, remove special characters, filter sensitive words, etc. Regex can efficiently complete these tasks. Verify cleaning rules in tester to ensure useful data is not mistakenly deleted.

6Learning Regular Expressions

For beginners, regex syntax can be quite complex. Using the tester, you can intuitively see the effect of each syntax element, learning through experimentation. Try modifying patterns, observe changes in match results. Use common pattern examples and quick reference to gradually master various regex features.

使用技巧与最佳实践 / Tips & Best Practices

Understanding Greedy vs Non-Greedy Matching

Quantifiers (*, +, ?, {n,m}) are greedy by default, matching as much as possible. For example, .* matches to the end. Adding ? after quantifier makes it non-greedy, matching as little as possible. For example, .*? matches to the first position that satisfies the condition. Understanding this difference is very important for correct matching. Compare greedy and non-greedy effects in the tester.

Using Capture Groups

Parentheses () create capture groups that can extract matched substrings. For example, (\d{4})-(\d{2})-(\d{2}) can separately capture year, month, day. The tester displays content of each group. Non-capturing groups (?:...) only group without capturing, better performance. Named capture groups (?<name>...) can name groups, more readable.

Escaping Special Characters

Special characters in regex (. * + ? ^ $ { } [ ] ( ) | \) need to be escaped with backslash to match literal values. For example, to match a period use \. not . (period matches any character). Inside character classes [], most special characters do not need escaping. Common error is forgetting to escape, causing unexpected match results.

Performance Optimization Tips

Complex regex can cause performance issues, especially with excessive backtracking. Optimization tips: 1) Use non-capturing groups to reduce overhead; 2) Avoid nested quantifiers (like (a+)+); 3) Use character classes instead of multiple alternatives ([abc] is faster than (a|b|c)); 4) Anchor pattern start (^) to reduce attempts; 5) Watch performance when testing large text.

Common Errors and Pitfalls

1) Forgetting to escape special characters; 2) Confusing greedy and non-greedy matching; 3) Ignoring case (need i flag); 4) Behavior of ^ and $ in multiline text (need m flag); 5) Dot not matching newlines (need s flag); 6) Unicode character handling (need u flag). Using the tester helps quickly discover these issues.

常见问题 / Frequently Asked Questions

技术说明 / Technical Details

This tool uses JavaScript native regex engine, providing real-time regex testing functionality. **Core Features**: 1. Real-time syntax validation and error prompts 2. Supports all JavaScript regex flags (g, i, m, s, u, y) 3. Highlights all match results 4. Displays detailed information for each match (content, position, capture groups) 5. Provides common pattern examples (email, phone, URL, IP, date, color) 6. Quick reference table (character classes, quantifiers, anchors) 7. One-click copy match results **Technical Implementation**: - Uses JavaScript RegExp object for matching - Real-time input change monitoring, auto-updates results - Uses exec() method to get detailed match information - Supports global matching (g flag) and single matching - Safely handles infinite loops (zero-width matches) - Uses HTML mark tag to highlight matched text **Supported Syntax**: - Character classes: \d, \w, \s, ., [abc], [^abc], [a-z] - Quantifiers: *, +, ?, {n}, {n,}, {n,m}, non-greedy *?, +?, ?? - Anchors: ^, $, \b, \B - Groups: (), (?:), (?<name>) - Assertions: (?=), (?!), (?<=), (?<!) - Alternation: | - Escapes: \, \n, \t, \r, \u{xxxx} **Performance Optimization**: - Limits match count to prevent freezing - Asynchronous processing of large text - Caches regex objects - Optimizes DOM updates **Privacy Protection**: All testing is done locally in browser, no data sent to servers. Does not store any user-entered regex or test strings. Fully protects your privacy. **Tech Stack**: Next.js + React + TypeScript + JavaScript RegExp API, ensuring accuracy and performance.

🔒 隐私保护承诺 / Privacy Protection

所有处理都在您的浏览器本地完成,数据不会上传到任何服务器。您的隐私和数据安全是我们的首要任务。
All processing is done locally in your browser. No data is uploaded to any server. Your privacy and data security are our top priorities.