JavaScript regex sandbox with live highlights
マッチをリアルタイムでハイライト。g/i/mフラグとキャプチャグループに対応。
Matches highlighted — 2 matches found
Match Details
hello@example.comidx 14support@tools.ioidx 35JavaScript regex sandbox with live highlights
Dialect differs from PCRE or POSIX—verify lookbehind support in your target engines. Use flags g/i/m/s deliberately: dotAll (s) changes “.” semantics dramatically.
Redact PII before sharing regex screenshots; logs often contain emails and phone numbers.
How the tester works
Type the pattern without surrounding slashes, toggle flags, and paste the text to search. The pattern runs on your browser’s own JavaScript RegExp engine on every keystroke, so what you see is exactly how the same pattern behaves in JavaScript and TypeScript code.
All matches are listed even if the g flag is off — the tester adds it internally for the list — together with each match’s position and its capture groups in order. Matches are highlighted in the text below. Patterns that can match an empty string, such as a* or \b, are stepped through one position at a time, so they show zero-width matches without freezing the page.
Five presets (email, URL, IPv4, date and hex colour) load a working pattern with sample text — useful starting points to adapt rather than definitive validators.
Worked examples
- Prices: \$\d+(?:\.\d{2})? on “Coffee $4.50, bagel $3, total $7.50” matches $4.50, $3 and $7.50. The dollar sign and the dot are escaped because both are special characters; (?: … ) groups the cents without capturing them.
- Dates with groups: (\d{4})-(\d{2})-(\d{2}) on “Due 2026-10-01” gives one match with groups 2026, 10 and 01 — in code, a replacement string such as $3/$2/$1 reorders them to 01/10/2026.
- Whole words: \bcat\b on “cat concatenate cat.” matches the two standalone words and skips “concatenate”.
- Log lines: ^ERROR.*$ with the m flag matches every line that starts with ERROR. Without m, ^ and $ only match the start and end of the whole text.
- Greedy vs lazy: <.+> on “<b>bold</b>” matches the entire string, because .+ grabs as much as it can. <.+?> matches “<b>” and “</b>” separately.
Mistakes that cause most regex bugs
- Unescaped dots: example.com matches “exampleXcom” too. Write example\.com.
- Missing anchors when validating: \d{5} finds five digits inside “123456789”. For a whole-input check use ^\d{5}$.
- Catastrophic backtracking: nested quantifiers such as (a+)+$ take exponential time on input like “aaaaaaaaaaaaaaaaaaaaaaaa!”. In a browser that freezes the tab — here as well as in production. Rewrite with a single quantifier — a+$ instead of (a+)+$ — or a more specific character class.
- Expecting regex to fully validate emails or parse HTML: the email preset accepts typical addresses, not every address RFC 5322 allows, and nested HTML needs a real parser.
- Forgetting flags: case-sensitive matching is the default — add i if “Error” and “ERROR” should both match.
Moving a pattern to another language
Most everyday syntax — character classes, quantifiers, groups, anchors, lookahead — is identical across JavaScript, Python, Java, C#, PHP and Go. The differences that bite are mostly about escaping and a few advanced features:
- String escaping: in Java and C# source code every backslash is doubled (“\\d+”); in Python use a raw string, r"\d+".
- Named groups: JavaScript, .NET and Java write (?<year>\d{4}); Python writes (?P<year>\d{4}).
- Go (RE2) has no lookahead, lookbehind or backreferences, by design, in exchange for guaranteed linear-time matching.
- PHP’s preg_ functions need delimiters around the pattern, for example /\d+/i.
- Lookbehind (?<=…) works in all current browsers and Node.js, but very old browsers lack it.
Privacy
Patterns and test text are processed only in your browser. Log excerpts often contain email addresses, IP addresses and tokens; you can test against them here without them leaving your machine, but scrub them before sharing a screenshot.
In-depth guides
- Regex Cheat Sheet: Tested Examples (JavaScript)
Character classes, quantifiers, groups, lookarounds and flags, with patterns for dates, prices, colours and URLs — every example tested in a JavaScript engine.
Related tools
These free tools pair well with this page — open them in a new tab to finish your workflow.
よくある質問
このツールはどの正規表現エンジンを使用しますか?
ブラウザに内蔵されたJavaScriptのRegExpエンジンを使用しています。JavaScriptの正規表現は文字クラス・量詞・先読み・グループ・後方参照などの主要機能をサポートしています。PCREにある可変長の後読みや原子グループなどは一部対応していません。
正規表現フラグの意味は何ですか?
主なフラグ:g(グローバル——最初だけでなくすべてのマッチを検索)、i(大文字小文字無視)、m(マルチライン——^と$が各行の先頭/末尾にマッチ)、s(dotAll——.が改行にもマッチ)、u(Unicode——完全なUnicodeサポートを有効化)。
リテラルのドットや特殊文字をマッチさせるには?
バックスラッシュでエスケープします。正規表現のドット(.)は任意の文字にマッチします。リテラルのドットをマッチさせるには\と書きます。同様に\、(、)、[、]、{、}、*、+、?、^、$、|は各文字の前にバックスラッシュを付けます。
キャプチャグループと非キャプチャグループの違いは?
キャプチャグループ(括弧:())はマッチしたテキストをキャプチャし、$1、$2などとして参照できます。非キャプチャグループ(?:...)はキャプチャせずにグループ化します。量詞を適用したいがコンテンツをキャプチャしたくない場合に便利です。
先読みと後読みとは何ですか?
先読み(?=...)は文字を消費せずに現在位置の後にパターンが続くことを表明します。後読み(?<=...)は前にパターンがあることを表明します。例:\d+(?= dollars)は' dollars'の前の数字にマッチしますが、' dollars'はマッチ結果に含まれません。