Regex測試器
// 使用即時匹配測試和除錯正則表達式
即時匹配
輸入regex模式或測試字串時匹配結果即時更新。
視覺化結果
匹配的文字在測試字串中直接用彩色背景高亮顯示。
模式庫
快速插入郵箱、URL、電話號碼、IP位址、日期的常用regex模式。
// REGEX
JavaScript RegExp:
Regular expressions (regex) are patterns used to match character combinations in strings. JavaScript supports flags: g (global), i (case-insensitive), m (multiline), s (dotAll), and u (unicode).
Example:
/\\d+/g matches "abc123def456" → ["123", "456"]
Use Cases:
- >Form validation: email, phone, URL
- >Text search and replace
- >Data extraction and web scraping
- >Log file analysis
- >Input sanitization
>> FAQ
Q: What is regex?
A: A regular expression is a sequence of characters that defines a search pattern for string matching, searching, and replacing.
Q: What do flags mean?
A: g (global) finds all matches. i ignores case. m (multiline) makes ^ and $ match line starts/ends. s (dotAll) makes . match newlines. u (unicode) enables full Unicode.
Q: What are capture groups?
A: Capture groups are created with parentheses () in a regex pattern to capture matched text for later reference.
Q: Greedy vs lazy matching?
A: Greedy quantifiers (*, +, {n,}) match as much text as possible. Lazy quantifiers (*?, +?, {n,}?) match as little as possible.
Q: Common regex patterns?
A: Email: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,} | URL: https?://[^\\s]+ | IP: \\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b
// 其他語言
參考資料
我們如何確保結果正確
我們使用以下自動化測試驗證此工具。下方保留測試案例的原始名稱,方便查看實際斷言及重現。
- 驗證方法
- 對捕獲組、全局/忽略大小寫和 Unicode 零寬匹配比較結果與索引。
- 對比依據
- JavaScript 原生 RegExp.matchAll。
- 驗證範圍
- 兩者使用同一 JS 正則引擎;此項驗證頁面遍歷/展示邏輯,不是第二種正則引擎。
測試原始碼與案例(點選檔名檢視)
-
parser-reliability.test.js
- Regex tester: captures, global matching and zero-width Unicode matches agree with native matchAll
這些測試涵蓋列出的樣本和邊界,不代表所有輸入都已證明正確。往返測試和使用同一依賴套件的檢查,不屬於獨立交叉驗證。