Monu Tools

正規表示式測試器

即時針對你的文字測試正規表示式。查看每個高亮的符合項,包括捕獲群組和旗標。完全在你的瀏覽器中執行。

如何使用 正規表示式測試

  1. 01

    在模式欄位中輸入你的正規表示式。

  2. 02

    切換你需要的旗標(g、i、m、s、u)。

  3. 03

    輸入測試字串,查看高亮的符合項及其群組。

What the regex tester does

The regex tester lets you build and debug regular expressions against your own sample text, with matches highlighted live as you type. It is useful for validating input formats, extracting fields from logs, or testing a pattern before pasting it into code.

Everything runs in your browser, so your patterns and test text are never uploaded.

Which engine it uses

It uses the JavaScript regular-expression engine, the same one in every browser and in Node.js, so a pattern that works here works in your JavaScript and TypeScript code.

Flags and capture groups

Toggle the global, case-insensitive, multiline and other flags to change how a pattern matches. You see every match along with its capture groups, so you can confirm exactly what each part of the pattern is pulling out.

Differences across regex flavors

Other languages such as PCRE, Python and Go share most syntax but differ in some features, so a few advanced constructs may behave differently outside JavaScript. If a pattern works here but not in another language, an engine-specific construct is usually the reason.

常見問題

使用哪種正規表示式風格?

瀏覽器內建的 JavaScript(ECMAScript)引擎,因此結果與你的 JavaScript 和 TypeScript 程式碼一致。

各旗標是什麼意思?

g 符合所有出現,i 忽略大小寫,m 使 ^ 和 $ 在換行處符合,s 讓點號符合換行,u 啟用完整的 Unicode 處理。

如何跨多行符合?

啟用多行(m)旗標,使 ^ 和 $ 在每個換行處符合;如果你還需要點號符合換行字元,請加上 dotAll(s)旗標。

會顯示捕獲群組嗎?

會。每個符合項都會列出其編號捕獲群組,命名群組按名稱顯示,因此你能準確看到模式各部分捕獲了什麼。

為什麼我的模式在這裡有效,在其他語言中卻無效?

這裡使用 JavaScript 引擎。PCRE、Python 等共享大部分語法,但在後向斷言、命名群組和某些跳脫上有所不同,因此移植進階模式時要小心。

我的文字會被上傳嗎?

不會。模式和你的測試文字完全在你的瀏覽器中求值,永遠不會離開你的裝置。

來源

嵌入此工具

將此工具加入你自己的網站。複製下方的程式碼片段,它會自動保持最新。

<iframe src="https://monu.tools/embed/zh-Hant/regex-tester" width="100%" height="640" style="border:1px solid #e5e5e5;border-radius:12px;max-width:680px" loading="lazy" title="Monu Tools"></iframe>

相關工具