Regex tester
About this tool
Run regular expressions against input text and inspect matches. Everything executes in your browser; no data is sent anywhere.
Run test
—
How to use
- Enter the regular expression and flags.
- Press “Run test” to highlight matches in the input text.
Examples (ready-to-use regex patterns by category, 100+)
Basics / whitespace / lines
- Blank line only:
^\s*$(m) - Leading whitespace:
^\s+(m) - Trailing whitespace:
\s+$(m) - Trim leading/trailing whitespace:
^\s+|\s+$(m) - Consecutive whitespace (compress to one):
\s{2,} - Visible characters (non-whitespace):
\S+ - ASCII only:
^[\x00-\x7F]+$ - Printable ASCII:
^[\x20-\x7E]+$ - Contains non-ASCII:
[^\x00-\x7F] - Word boundary:
\bword\b
Numbers / currency
- Integer (optional sign):
^-?\d+$ - Decimal (optional sign):
^-?\d*\.\d+$ - Number (integer or decimal):
^-?(?:\d+|\d*\.\d+)$ - Thousands-separated (e.g., 1,234,567):
^\d{1,3}(?:,\d{3})+$ - Currency (¥ or $ with optional grouping):
^(?:¥|\$)\s?\d{1,3}(?:,\d{3})*(?:\.\d{2})?$ - Percentage:
^\d{1,3}(?:\.\d+)?% - Scientific notation:
^[+-]?(?:\d+\.?\d*|\.\d+)[eE][+-]?\d+$ - Hexadecimal:
^(?:0x)?[0-9A-Fa-f]+$ - Binary:
^[01]+$ - Octal:
^[0-7]+$
Dates / time
- Date YYYY-MM-DD (format only):
^\d{4}-\d{2}-\d{2}$ - Time HH:MM (24h):
^(?:[01]\d|2[0-3]):[0-5]\d$ - Time HH:MM:SS (24h):
^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$ - ISO8601 datetime (simplified):
^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$ - Year/month (YYYY/MM):
^\d{4}/(0[1-9]|1[0-2])$ - Japanese era (Reiwa, simplified):
^令和\d+年(?:\d+月(?:\d+日)?)?$(u) - Day of week (English, 3 letters):
^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)$ - Time zone (±HH:MM):
^[+-](?:[01]\d|2[0-3]):[0-5]\d$
Contacts / addresses (quick)
- Japan postal code:
^\d{3}-\d{4}$ - Japan phone (simple 0x-xxxx-xxxx):
^0\d{1,4}-\d{1,4}-\d{4}$ - International phone (+country code, spaced):
^\+\d{1,3}\s?\d+(?:[\s-]\d+)*$ - Japanese prefecture names:
^(?:東京都|北海道|(?:京都|大阪)府|.+県)$(u) - Email (common quick check):
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ - Username (3–16 letters/digits/_):
^[A-Za-z0-9_]{3,16}$ - Password strength (upper/lower/digit/symbol, length ≥ 8):
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{8,}$
Web / URL / HTTP
- URL (http/https quick check):
https?:\/\/\S+ - Domain (simple, no Punycode):
^(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,}$ - Host with subdomains:
^(?:[A-Za-z0-9-]+\.)*[A-Za-z0-9-]+\.[A-Za-z]{2,}$ - Query parameter key=value:
[?&]([A-Za-z0-9._~-]+)=([^&#]+) - Fragment:
#\w[\w-]* - File extension (.png|.jpg|.gif etc.):
\.(?:png|jpe?g|gif|webp|svg)$(i) - HTTP methods:
^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)$ - HTTP header line:
^[A-Za-z0-9-]+:\s?.+$(m) - Basic auth header:
^Basic\s+[A-Za-z0-9+/=]+$ - Bearer token header:
^Bearer\s+[A-Za-z0-9\-\._~\+\/]+=*$
Network (IP/MAC/CIDR/UUID/JWT etc.)
- IPv4 (0–255 strict):
\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\b - IPv6 (supports compression, simplified):
\b(?:[A-Fa-f0-9]{1,4}:){2,7}[A-Fa-f0-9]{1,4}\b - MAC address (: separated):
^(?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$ - MAC address (- separated):
^(?:[0-9A-Fa-f]{2}-){5}[0-9A-Fa-f]{2}$ - CIDR (IPv4 length 0–32):
^\b(?:\d{1,3}\.){3}\d{1,3}\/(?:[0-9]|[12]\d|3[0-2])\b$ - UUID v4:
^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$(i) - GUID (case-insensitive):
^{?[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}}?$(i) - Base64 (with padding):
^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$ - JWT (three dot-separated segments):
^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+$ - SSH public key (ssh-rsa/ed25519):
^ssh-(?:rsa|ed25519)\s+[A-Za-z0-9+/=]+(?:\s.+)?$
Files / paths / versions
- Windows absolute path:
^[A-Za-z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$ - UNIX absolute path:
^\/(?:[^\/\0]+\/)*[^\/\0]*$ - Safe filename (letters/digits ._- only):
^[A-Za-z0-9._-]+$ - Capture file extension:
\.([A-Za-z0-9]+)$ - Git hash (7–40 chars):
^[0-9a-f]{7,40}$ - SemVer:
^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$ - Docker image:tag:
^[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[\w.-]+)?$ - NPM package name (simple):
^(?:@[\w-]+\/)?[\w.-]+$ - URL slug:
^[a-z0-9]+(?:-[a-z0-9]+)*$
Web front-end (HTML/CSS/colors)
- HTML tag (paired start/end, simple):
<([A-Za-z][A-Za-z0-9]*)\b[^>]*>([\s\S]*?)<\/\1> - HTML comment:
<!--[\s\S]*?--> - href attribute value:
href\s*=\s*"(.*?)"(i) - CSS color (#RGB/#RRGGBB):
^#(?:[0-9A-Fa-f]{3}){1,2}$ - CSS rgb():
^rgb\(\s*(?:[01]?\d?\d|2[0-4]\d|25[0-5])\s*,\s*(?:[01]?\d?\d|2[0-4]\d|25[0-5])\s*,\s*(?:[01]?\d?\d|2[0-4]\d|25[0-5])\s*\)$ - CSS hsl():
^hsl\(\s*(?:\d|[1-2]\d{2}|3[0-5]\d)\s*,\s*(?:\d|[1-9]\d)%\s*,\s*(?:\d|[1-9]\d)%\s*\)$ - CSS unit (px, em, etc.):
^-?\d+(?:\.\d+)?(?:px|em|rem|vh|vw|%)$
Strings / syntax (programming snippets)
- JavaScript identifier (simple):
^[A-Za-z_$][A-Za-z0-9_$]*$ - JavaScript // comment line:
^\s*\/\/.*$(m) - JavaScript block comment:
\/\*[\s\S]*?\*\/ - Double-quoted string (simple escape handling):
"(?:[^"\\]|\\.)*" - Single-quoted string:
'(?:[^'\\]|\\.)*' - Template literal (simplified):
`(?:[^`\\]|\\.|\\${[^}]*})*` - JSON key:
"([A-Za-z0-9_]+)"\s*: - CSV cell (handles double quotes):
(?:"(?:[^"]|"")*"|[^,\r\n]*) - Extract URLs from email body:
https?:\/\/[^\s)>"]+
Security / validation (use carefully)
- Credit card (no Luhn, quick check):
\b(?:\d[ -]*?){13,19}\b - VISA (starts with 4, 13/16/19 digits):
\b4\d{12}(?:\d{3})?(?:\d{3})?\b - Mastercard (51–55 / 2221–2720):
\b(?:5[1-5]\d{14}|2(?:2[2-9]\d{2}|[3-6]\d{3}|7[01]\d{2}|720\d{2})\d{10})\b - Japan MyNumber (format only, no checksum):
^\d{12}$ - Postal code + address line (simple):
^\d{3}-\d{4}\s+.+$ - XSS <script> tag detection (simple):
<\s*script\b[^>]*>[\s\S]*?<\s*\/\s*script\s*> - SQL keywords (quick check):
\b(SELECT|INSERT|UPDATE|DELETE|DROP|ALTER|CREATE)\b(i)
Note: Confirm legal and internal policies before using these patterns on personal or confidential data.
Log formats
- Apache/Nginx CLF (simple):
^(\S+)\s+(\S+)\s+(\S+)\s+\[([^\]]+)\]\s+"([^"]+)"\s+(\d{3})\s+(\d+|-) - ISO8601 timestamp:
\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2}) - JSON line (one JSON per line):
^\{.*\}$(m) - UUID capture:
[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}(i) - Extract IPv4 (simple):
\b(?:\d{1,3}\.){3}\d{1,3}\b
Markdown
- Headings (#–######):
^(#{1,6})\s+(.+)$(m) - Link:
\[([^\]]+)\]\(([^)]+)\) - Image:
!\[([^\]]*)\]\(([^)]+)\) - Inline code:
`([^`]+)` - Code block (```…``` simple):
```[\s\S]*?``` - Bullet list (- * +):
^\s*[-*+]\s+.+$(m) - Blockquote >:
^\s*>\s+.+$(m)
Japanese scripts / character classes (use Unicode flag)
- Hiragana only:
^[\u3041-\u3096]+$(u) - Katakana only:
^[\u30A1-\u30FA\u30FC]+$(u) - Half-width katakana only:
^[\uFF66-\uFF9D\uFF70]+$(u) - Contains kanji:
[\u4E00-\u9FFF](u) - Full-width characters only:
^[^\x00-\x7F]+$ - Full-width alphanumerics:
^[\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A]+$(u) - Postal code (accepts full-width digits):
^[0-9\d]{3}-[0-9\d]{4}$(u) - Furigana (full-width kana):
^[\u30A1-\u30FA\u30FC\s]+$(u)
Text formatting / extraction utilities
- Remove leading numbering “1.”:
^\s*\d+\.\s*(m) - Strip bullet prefixes:
^\s*(?:[-*+]|•|\d+\.)\s*(m) - Capture inside parentheses:
\(([^)]*)\) - Capture inside double quotes:
"([^"\\]|\\.)*" - Extract Japanese yen “¥123,456”:
¥\s?\d{1,3}(?:,\d{3})* - Extract email domain:
@([A-Za-z0-9.-]+\.[A-Za-z]{2,}) - Remove HTML tags (simple):
<[^>]+> - Collapse repeated spaces:
\s{2,}
Other useful
- Japanese license plate (very simple):
^[\u3041-\u3096\u30A1-\u30FA\u4E00-\u9FFF]{1,2}\s?\d{3,4}$(u) - YouTube video ID:
(?<=v=|youtu\.be\/)[A-Za-z0-9_-]{11} - Twitter/X user @handle:
@[A-Za-z0-9_]{1,15} - Slack channel:
#[a-z0-9_-]{1,80} - Color names (sample CSS keywords):
\b(?:red|green|blue|black|white|gray|silver|maroon)\b(i) - Bracketed annotations 〔…〕:
[([^]]*)]|【([^】]*)】|〔([^〕]*)〕(u) - Detect half-width kana:
[\uFF61-\uFF9F](u) - English word (allowing hyphen):
\b[A-Za-z]+(?:-[A-Za-z]+)*\b - Order number in email (e.g., #12345):
#\d{4,} - Japanese station names (ending with “駅”):
.+駅\b(u)
Note: These patterns aim to be practical and ready to paste. For strict validation (leap years, IDNs, full HTML parsing, etc.), use specialized logic or libraries.