Regex Tester

Kiểm tra biểu thức chính quy.
//

Live Matching

Highlights matches as you type the pattern.

Capture Groups

Shows numbered groups for each match.

Flag Toggles

Global, case-insensitive, multiline, dotAll.

Client-side

All processing in your browser. No data uploaded.

Giới thiệu về Regex Tester

Regular expressions (regex) are powerful patterns used to search, match, and manipulate text. They are an essential skill for software developers, data engineers, and system administrators — used everywhere from form validation and log parsing to URL routing and find-and-replace operations in code editors. This regex tester lets you write and debug JavaScript-flavoured regular expressions in real time. Type a pattern in the input field, add optional flags, then enter your test string in the textarea below. All matches are highlighted inline with distinct colours so you can see exactly what your pattern captures. A match detail panel below lists each match with its character index and any captured groups. Four flags are supported: g (global — find all matches), i (case-insensitive), m (multiline — ^ and $ match line boundaries), and s (dotAll — makes . match newline characters). Errors in your pattern are displayed immediately with a clear message, helping you iterate quickly without guessing what went wrong.

Làm sao để Regex Tester?

  1. Type your regular expression pattern between the two slash delimiters in the pattern field.
  2. Toggle the g, i, m, or s flag buttons to enable global matching, case-insensitivity, multiline mode, or dotAll mode.
  3. Paste or type your test string in the large textarea below the pattern field.
  4. Matches are highlighted in the text immediately — different colours distinguish multiple matches.
  5. Check the match list below the highlighted text to see each match, its position, and any capture groups.
  6. Refine your pattern until it matches exactly what you need, then copy it to use in your code.

Câu hỏi thường gặp

Which regex flavour does this tool use?

This tool uses JavaScript's built-in RegExp engine (ECMAScript flavour). It supports most common features including lookaheads, lookbehinds, named capture groups, and Unicode — but not some PCRE-specific features like conditionals or atomic groups.

What does the g flag do?

The global (g) flag tells the engine to find all matches in the string instead of stopping after the first one. Without it, you'd only see the very first match.

How do I use capture groups?

Wrap part of your pattern in parentheses — for example (\d+) — to create a capture group. The matched text inside the group is shown separately in the Groups column of each match result.

Why does my pattern work here but not in my code?

Make sure you're applying the same flags in your code as you set here. Also note that in JavaScript string literals you need to double-escape backslashes (\\d instead of \d) when constructing a RegExp from a string.

What is the dotAll (s) flag?

By default, the dot (.) in a regex does not match newline characters. Enabling the s (dotAll) flag changes this so that . matches any character including \n and \r, which is useful for matching multi-line content.

Kiểm Tra Biểu Thức Chính Quy (Regex Tester) Online: Highlight Kết Quả Thời Gian Thực

Soạn thảo, kiểm tra và gỡ lỗi Regular Expressions trực quan kèm giải thích chi tiết và cheat-sheet

Vấn đề thường gặp & Giải pháp

Biểu thức chính quy (Regex) là công cụ cực kỳ mạnh mẽ nhưng cũng nổi tiếng phức tạp và khó nhớ. Chỉ một lỗi nhỏ về cờ (flags), ký tự escape hoặc capture group có thể dẫn đến lỗi logic bảo mật hoặc sập hiệu năng (ReDoS).

Metoolzy Regex Tester mang đến môi trường kiểm tra biểu thức chính quy trực quan, hỗ trợ highlight kết quả khớp (Match) ngay khi bạn gõ, phân tích chi tiết từng nhóm bắt (Capture Groups) và hỗ trợ đầy đủ các cờ g, i, m, s, u.

Tính Năng Nổi Bật Của Regex Tester

  • Highlight thời gian thực: Đánh dấu các chuỗi ký tự khớp ngay lập tức trong văn bản mẫu.
  • Hỗ trợ Capture Groups: Phân biệt rõ ràng Group 0 (Toàn bộ match), Group 1, Group 2 với màu sắc riêng biệt.
  • Tùy chọn cờ linh hoạt: Dễ dàng bật/tắt các cờ Global (g), Case-insensitive (i), Multiline (m), DotAll (s).
  • Thư viện mẫu Regex phổ biến: Tích hợp sẵn các biểu thức chuẩn cho Email, Số điện thoại, URL, Ngày tháng, Địa chỉ IPv4/IPv6.

Hướng Dẫn Sử Dụng Từng Bước

  1. Nhập biểu thức Regex của bạn vào thanh mẫu (Pattern bar).
  2. Chọn các cờ cần áp dụng (Global, Insensitive, Multiline).
  3. Dán văn bản thử nghiệm vào khung bên dưới để xem kết quả highlight và danh sách capture groups.

Bảng So Sánh Chi Tiết

Ký tự Regex Ý nghĩa Ví dụ
^ và $ Bắt đầu và kết thúc chuỗi/dòng ^hello$
[0-9] hoặc \d Ký tự số bất kỳ \d{4} (khớp 4 chữ số)
[a-zA-Z] Chữ cái in hoa hoặc thường [A-Z]+
+ và * +: 1 hoặc nhiều lần; *: 0 hoặc nhiều lần a+ khớp a, aa, aaa
( ) Tạo Capture Group (\d{2})-(\d{2})

Trường Hợp Ứng Dụng Thực Tế

  • Lập trình viên viết hàm validate form (Email, Password, SĐT)
  • Data Analysts trích xuất dữ liệu có cấu trúc từ log file
  • SEOers cấu hình chuyển hướng 301 Regex trong file .htaccess và Nginx

Câu Hỏi Thường Gặp (FAQ)

Công cụ sử dụng engine Regex nào?

Công cụ sử dụng chuẩn JavaScript RegExp chuẩn ECMAScript hiện đại nhất, hỗ trợ lookahead, lookbehind và Unicode flags.

Làm sao để tìm kiếm không phân biệt chữ hoa chữ thường?

Hãy bật cờ i (Case-insensitive) trên thanh công cụ.