テキスト
Regex Tester / Find & Replace
実際のテキストで正規表現をテスト:マッチ箇所のハイライトとキャプチャグループの解析、または見つかったマッチを新しいテキストに置換。
A regular expression (regex) is a compact language for describing patterns in text — for searching, validating a format, or replacing matches. This tool highlights matches in real text as you type the pattern, breaks out capture groups, and supports a find-and-replace mode.
How to use it
- Search: enter a pattern and some test text — every match is highlighted and capture groups are broken out separately.
- Replace: switch to Replace mode, provide a replacement template (referencing groups with $1, $2), and see the result instantly.
- Flags (g, i, m, s) toggle independently and immediately affect how many matches are found and how.
Common uses
- Building and debugging a regex before pasting it into code — you see the result without running the program.
- Bulk find-and-replace against a pattern (e.g. reformatting phone numbers or dates).
- Validating an input format (email, card number, slug) against real examples.
Things to keep in mind
Greedy quantifiers (*, +) grab as many characters as possible — add ? for the minimal match instead (e.g. .*? instead of .*).
Syntax varies slightly between languages — an expression that works here (a JavaScript engine) may need adjusting for PCRE, .NET, or Python.
よくある質問
どのregexエンジンが使われていますか?
このツールはPCREではなくJavaScriptのregexエンジンを使用しているため、一部のPCRE固有の構文(再帰的アサーションや特定の所有的マッチングモードなど)はここでは機能しません。g、i、m、s、uなどの一般的なフラグはサポートされています。
貪欲な量指定子と怠惰な量指定子の違い、およびTestとReplaceの違いは何ですか?
*や+のような貪欲な量指定子はできるだけ多くのテキストをキャプチャしますが、その怠惰なバージョン(*?、+?)はできるだけ早く停止します。モードについては、Testは一致をハイライトし、キャプチャグループ(名前付きを含む)をリストし、Replaceは各一致に$1のような参照を使った置換テキストを適用します。
私のテキストと式はサーバーに送信されますか?
いいえ、正規表現の評価はブラウザ内で完全にクライアントサイドで行われ、オンラインには何も送信されません。
破滅的バックトラッキングとは何ですか?
(a+)+のようなネストした数量詞は、特定の入力文字列に対してエンジンに指数関数的な数の組み合わせを試させることがあります — 一見単純に見える式で、ページやスクリプトが「フリーズ」してしまいます。これは実際の脆弱性(ReDoS)であり、複雑なネストした数量詞は長いほぼ一致する文字列に対してテストすべきです。
なぜ私の正規表現はあるプログラミング言語では動くのに、別の言語では動かないのですか?
regexの構文は完全には標準化されていません: PCRE(PHP、その他多くの言語)、.NET、Python re、JavaScriptは、特定の構文(look-behindや名前付きグループなど)のサポートに細かな違いがあります — あるエンジン向けに書かれた式が、別のエンジンでそのまま動くとは限りません。