Regex Tester
正規表現をリアルタイムでテストし、マッチ結果をハイライト表示します。
このツールはJavaScript (ECMAScript) の正規表現構文でテストします。
複雑なパターンを長い文字列に対して実行すると、ブラウザが重くなる場合があります。詳しくは正規表現のReDoSとは何かをご覧ください。
How to Use the Regex Tester
This free online regex tester lets you write and test regular expressions in real time with instant match highlighting. Enter your pattern in the regex field, set your desired flags, and type or paste your test string. Matches are highlighted immediately as you type, and a detailed match table shows each match along with its position and captured groups. All processing runs entirely in your browser using the native JavaScript RegExp engine.
Understanding Regex Flags
JavaScript supports several regex flags that modify matching behavior. g (global) finds all matches rather than stopping at the first one. i (case-insensitive) ignores case when matching letters. m (multiline) makes ^ and $ match the start and end of each line rather than the entire string. s (dotAll) makes the dot character match newline characters as well. u(unicode) enables full Unicode matching. You can combine multiple flags, for example "gi" for global case-insensitive matching.
Common Regex Patterns
Some commonly used patterns include \d+ for matching numbers, [a-zA-Z]+ for matching words, \b\w+@\w+\.\w+\b for basic email matching, and https?:\/\/\S+ for matching URLs. Captured groups using parentheses are shown in the match details table, making it easy to extract specific parts of your matches.
Tips for Writing Regex
Start simple and build complexity gradually. Use the real-time highlighting to verify each part of your pattern works before adding more. Remember to escape special characters like dots, brackets, and backslashes with a backslash when you want to match them literally. Captured groups with parentheses allow you to extract substrings from matches, which is useful when parsing structured text like log files or CSV data.
正規表現テスターの使い方
パターン欄に正規表現を入力し、テスト文字列を貼り付けるとリアルタイムでマッチ箇所がハイライト表示されます。 フラグ(g, i, mなど)を組み合わせて検索動作を変更でき、マッチ詳細テーブルで各マッチの位置やキャプチャグループも確認できます。 全ての処理はブラウザ内で完結し、データが外部に送信されることはありません。
すぐ使えるパターン
- 日本の郵便番号:
/^\d{3}-?\d{4}$/ - メールアドレス(現実解):
/^[^\s@]+@[^\s@]+\.[^\s@]+$/ - URL抽出:
/https?:\/\/\S+/g - 全角英数を半角に寄せる前処理には
String.prototype.normalize("NFKC")を併用
さらに多くの実例・ハマりどころは正規表現の実例集に まとめています。郵便番号・電話番号・和暦・クレジットカード番号など、日本でよく使うパターンを コピペできる形で掲載しています。
よくあるエラーと対処 / Common Errors and Fixes
| 症状 / Symptom | 原因 / Cause | 対処 / Fix |
|---|---|---|
| Safari/旧ブラウザで動かない Fails on Safari/older browsers | lookbehind (?<=...) 非対応No lookbehind support | 対応状況を確認し、match+slice で回避 Feature-detect; fall back to match+slice |
Nothing to repeat | */+ の前に何もないQuantifier with no target | 文字クラスを足すかエスケープ(\*)Add a target or escape the meta-char |
| 全角英数にマッチしない Full-width chars don't match \w | \w=ASCII のみ\w is ASCII-only | 事前に normalize("NFKC")Normalize with normalize("NFKC") first |
| 長文で固まる Hangs on long input (ReDoS) | ネストされた量指定子 Nested quantifiers (catastrophic backtracking) | 所有量指定 or 線形エンジン(re2/safe-regex) Rewrite to avoid ambiguity; use re2 |
| 絵文字を 1 文字として扱えない Emoji counted as 2 chars | サロゲートペア扱い UTF-16 surrogate pairs | u フラグ + \p{...}Use the u flag with \p{...} |
言語別コード例 / Code Examples by Language
JavaScript
// Global match
const hits = text.match(/\d+/g) ?? [];
// Named capture
const m = "2026-04-19".match(/(?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})/);
console.log(m?.groups); // { y: "2026", m: "04", d: "19" }
// Replace
const slug = title.toLowerCase().replace(/[^a-z0-9]+/g, "-");Python
import re
m = re.search(r"(?P<y>\d{4})-(?P<m>\d{2})-(?P<d>\d{2})", s)
if m: print(m.group("y"), m.group("m"), m.group("d"))
# All matches
nums = re.findall(r"\d+", s)Go
import "regexp"
re := regexp.MustCompile(`\d+`)
for _, n := range re.FindAllString(s, -1) { /* ... */ }Shell (grep -E)
grep -Eo '[0-9]{3}-[0-9]{4}' file.txt上記は各言語での書き方の例です。実際にテストする際は、本ツールがJavaScript構文で動作する点にご注意ください(言語によって正規表現の細部が異なる場合があります)。
Before / After 実例 / Before & After
例1: 郵便番号の抽出 / Extract Japanese postal codes
Input : "〒100-0001 東京都千代田区、〒150-0002"
Regex : /\d{3}-\d{4}/g
Match : ["100-0001", "150-0002"]例2: URL 抽出 / Extract URLs
Input : "参考: https://devtoolspot.com と http://example.com"
Regex : /https?:\/\/\S+/g
Match : ["https://devtoolspot.com", "http://example.com"]例3: キャッシュバスター削除 / Strip cache-buster query
Input : "style.css?v=1234567"
Regex : /\?v=\d+$/
Replace with "" → "style.css"Why browser-only? / なぜブラウザ完結か
Regex work usually means testing patterns against real log lines, user input, or production strings — which often carry PII, session IDs, or internal URLs. DevToolBox runs RegExplocally using your browser's JavaScript engine. No sample strings travel over the network.
正規表現の検証は、生のログ・ユーザー入力・本番文字列を対象にすることが多く、 PII、セッション ID、内部 URL が混ざります。DevToolBox はブラウザの JavaScript エンジンでRegExp を実行します。サンプル文字列はネットワークに出ません。
関連ガイド / Related Guides
関連ツール / Related Tools
開発をもっと効率的に
PR
レンタルサーバー
エックスサーバー
国内シェアNo.1の高速レンタルサーバー(エックスサーバー社調べ)。WordPressも簡単セットアップ。
詳しく見る →レンタルサーバー
ConoHa WING
国内最速クラスのレンタルサーバー。独自ドメイン永久無料特典付き(特典内容は変更される場合があります)。
詳しく見る →レンタルサーバー
mixhost
高速SSD・HTTP/3対応のクラウド型レンタルサーバー。
詳しく見る →VPS
シンVPS
メモリ単価国内最安・オールNVMe SSD搭載の高性能VPS。開発・検証環境の構築に。
詳しく見る →Windows VPS
ConoHa for Windows Server
Windows環境のVPS。リモートデスクトップで開発・検証環境を構築。
詳しく見る →