What to do next
- Pick something close under "Start from an example". The pattern goes in, along with examples that should and shouldn't match.
- Paste a few lines of your own data into "Test text". Matches get a yellow highlight, and lines with a match get a green bar on the left.
- If a line you don't want gets highlighted, fix the pattern. "How to read this pattern" shows what each part matches.
- When you're done, press "Copy the pattern" to copy it in /…/ form. To show someone, use "Link to share".
The examples
Press "Try" to put a pattern and its examples in the boxes above. Every example comes with text that should match and text that shouldn't (or with text to search).
Japanese formats
| Name | Pattern | Flags | What it matches, and what to watch | Try |
|---|---|---|---|---|
| Japanese postcode | ^\d{3}-?\d{4}$ | gm | Seven digits, with an optional hyphen between the third and fourth. Full-width digits and full-width hyphens don't match, so convert them to half-width first if you use this for input checks. | |
| Find postcodes in text | \b\d{3}-\d{4}\b | g | \b is the boundary between a digit and a non-digit, so it doesn't match inside longer numbers (the 234-5678 in 1234-56789). | |
| Landline number (with hyphens) | ^0(\d-\d{4}|\d{2}-\d{3}|\d{3}-\d{2}|\d{4}-\d)-\d{4}$ | gm | A Japanese landline number is 0, then an area code and a local code that together make 5 digits, then a 4-digit subscriber number: 10 digits in all. This matches the four ways of splitting it. It doesn't check whether the area code exists. | |
| Mobile number | ^0[6-9]0-?[1-9]\d{3}-?\d{4}$ | gm | 11 digits starting with 060, 070, 080 or 090, with a fourth digit that isn't 0. 060 was added to the mobile numbers in December 2024. | |
| Phone number (no hyphens) | ^0\d{9,10}$ | gm | 10 or 11 digits starting with 0. It doesn't check the kind of number. Use it after taking the hyphens out. | |
| Toll-free number (0120, 0800) | ^(0120-?\d{3}-?\d{3}|0800-?\d{3}-?\d{4})$ | gm | Numbers starting with 0120 have 10 digits, and numbers starting with 0800 have 11. | |
| Invoice registration number | ^T\d{13}$ | gm | A capital T followed by 13 digits. To see whether a number is actually registered, check the National Tax Agency's publication site. | |
| Date (2026-11-28, 2026/11/28) | ^\d{4}[-/](0?[1-9]|1[0-2])[-/](0?[1-9]|[12]\d|3[01])$ | gm | Months 1 to 12 and days 1 to 31 match, so dates that don't exist, like February 30, match too. Check that a date is real in your program. | |
| Time (24-hour) | ^([01]?\d|2[0-3]):[0-5]\d$ | gm | Hours 0 to 23 (one or two digits) and minutes 00 to 59 (two digits). | |
| Amount (commas every three digits) | ^(0|[1-9]\d{0,2}(,\d{3})*)$ | gm | Matches numbers with commas correctly placed every three digits. Numbers of four or more digits without commas (1200) don't match. | |
| Split a Japanese address into prefecture and the rest | ^(東京都|北海道|(?:京都|大阪)府|.{2,3}県)(.+)$ | gm | Group 1 gets the prefecture and group 2 the rest. Tokyo, Hokkaido, Kyoto and Osaka are named; any other prefecture is taken as its 2 or 3 characters plus the character for prefecture. It doesn't check whether the prefecture exists. |
Character types
| Name | Pattern | Flags | What it matches, and what to watch | Try |
|---|---|---|---|---|
| Hiragana only | ^[ぁ-んー]+$ | gm | Matches hiragana from the small a to n, plus the long-vowel mark. Spaces don't match. | |
| Full-width katakana only | ^[ァ-ヶー]+$ | gm | Matches full-width katakana from the small a to the small ke (vu included), plus the long-vowel mark. Half-width katakana and spaces don't match. | |
| Furigana (a space between family and given name) | ^[ァ-ヶー]+([ \u3000][ァ-ヶー]+)*$ | gm | Allows a single half-width or full-width space between runs of full-width katakana. \u3000 is the full-width space. | |
| Find half-width katakana | [ヲ-゚]+ | g | Finds runs of half-width katakana (wo through the handakuten, voicing marks included). Useful as a check before converting to full-width. | |
| Kanji only | ^\p{Script=Han}+$ | gmu | \p{Script=Han} matches the characters Unicode counts as kanji (the repetition mark included). It needs the u flag. | |
| Find full-width letters and digits | [A-Za-z0-9]+ | g | Finds runs of full-width letters and digits. | |
| Find full-width spaces | \u3000 | g | \u3000 is the full-width space. This shows where full-width spaces are, which are hard to spot by eye. | |
| Half-width letters, digits and symbols only | ^[\x20-\x7E]+$ | gm | \x20-\x7E covers the half-width characters from the space to ~: ASCII letters, digits and symbols. | |
| Half-width digits only | ^\d+$ | gm | In JavaScript, \d matches only the half-width 0 to 9. It doesn't match full-width digits. | |
| Half-width letters and digits only | ^[A-Za-z0-9]+$ | gm | Symbols and spaces don't match. To allow underscores too, you can write ^\w+$. |
Web and form checks
| Name | Pattern | Flags | What it matches, and what to watch | Try |
|---|---|---|---|---|
| Email address | ^[\w.!#$%&'*+/=?^`{|}~-]+@[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?(?:\.[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?)*$ | gim | Follows the same idea as the check browsers use for email input fields (type="email"). Domains without a dot (taro@localhost) match too. | |
| Find URLs in text | https?://[\w/:%#$&?()~.=+@,;!*'-]+ | g | Finds text that starts with http:// or https:// followed by characters used in URLs. A half-width ) or . right after a URL can get caught too (the second example). | |
| At least 8 characters, with both letters and digits | ^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$ | gm | (?=…) only checks that what's inside comes next, without moving forward. Two in a row check for a letter and for a digit. |
Find and replace
| Name | Pattern | Flags | What it matches, and what to watch | Try |
|---|---|---|---|---|
| Reformat dates into the Japanese style | (\d{4})[/-](\d{1,2})[/-](\d{1,2})→ $1年$2月$3日 | g | The parts in ( ) can be used as $1, $2 and $3 in the replacement. | |
| Remove HTML tags | <[^>]+>→ (delete) | g | Removes everything from < to the next >. It doesn't work well on HTML with a > inside an attribute value. | |
| Trim spaces at the start and end of lines | ^[ \t\u3000]+|[ \t\u3000]+$→ (delete) | gm | Removes half-width spaces, tabs and full-width spaces from the start and end of each line. With the m flag, ^ and $ work on each line. | |
| Collapse runs of spaces into one | [ \u3000]{2,}→ one half-width space | g | Turns two or more half-width or full-width spaces in a row into a single half-width space. | |
| Collapse runs of blank lines into one | \n{3,}→ \n\n | g | Turns three or more line breaks in a row (two or more blank lines) into two (one blank line). \n in the replacement is treated as a line break. |
The rules for Japanese numbers
The example patterns check only the shape of a number. They're based on these rules.
| Kind | Rule | Example |
|---|---|---|
| Postcode | 7 digits, with a hyphen between the third and fourth | 100-0001 |
| Landline | 0 + area code (1 to 4 digits) + local code (1 to 4 digits) + subscriber number (4 digits). The area code and local code make 5 digits together, for 10 digits in all | 03-1234-5678 |
| Mobile | 11 digits starting with 060, 070, 080 or 090. The fourth digit isn't 0 | 090-1234-5678 |
| IP phone | 11 digits starting with 050. The fourth digit isn't 0 | 050-1234-5678 |
| 0120, 0570 and similar | 10 digits starting in the form 0AB0. Only 0800 numbers have 11 | 0120-123-456 |
| Invoice registration number | T + 13 digits | T1234567890123 |
Numbers starting with 060 were opened up for mobile phones in December 2024. Input checks that only let 070, 080 and 090 through reject 060 numbers. The "Mobile number" example lets 060 through too.
A number with the right shape isn't necessarily in use. Make a phone number check too strict, and people with real numbers can't enter them. When in doubt, a loose check such as "10 or 11 digits starting with 0" is the safe choice.
Japanese characters and \d, \w and \s
\d and \w in regular expressions were defined with English text in mind. If you use them on Japanese data, knowing what they do and don't match saves mistakes. These are the rules for regular expressions in JavaScript (in the browser).
| Written as | Matches | What to watch with Japanese data |
|---|---|---|
\d | Half-width 0 to 9 | Doesn't match full-width digits (123) |
\w | Half-width A to Z, a to z, 0 to 9 and _ | Doesn't match hiragana, katakana or kanji, so \w+ can't pick out Japanese words |
\s | Spaces, tabs, line breaks and so on, including the characters Unicode classes as spaces | Matches the full-width space too |
\b | The boundary between a character \w matches and one it doesn't | There are no boundaries between Japanese characters |
[ぁ-ん] | Hiragana (from ぁ to ん) | The long-vowel mark ー isn't included. Add it when you need it: [ぁ-んー] |
[ァ-ヶ] | Full-width katakana (from ァ to ヶ) | ー and ・ aren't included, and half-width katakana doesn't match |
[ヲ-゚] | Half-width katakana (the voicing marks ゙ and ゚ included) | A half-width ガ is two characters, カ and ゙ |
\p{Script=Han} | Kanji (the characters Unicode counts as kanji) | Needs the u flag. Matches the repetition mark 々 too. You can also write [一-龠], but that leaves out 々 |
A range such as [ぁ-ん] covers everything from the first character to the last in the order of their Unicode numbers, not in the order of the Japanese syllabary.
Flags (how to search)
| Flag | When ticked |
|---|---|
g | Finds every match. Without it, only the first match is found. |
i | Treats upper and lower case as the same letter. |
m | Makes ^ and $ match at the start and end of each line, instead of the whole text. Use it to check one value per line. |
s | Lets . match line breaks too. Without it, . never matches a line break. |
u | Enables Unicode syntax such as \p{Script=Han} (kanji), and treats characters such as emoji as one character. |
y | Only looks right after the previous match. If a non-matching character comes in between, it stops there. |
To check an input-validation pattern (one that starts with ^ and ends with $) against many example lines at once, tick both g and m. The examples are set up that way. When your program checks a single value, you need neither.
Replacing
Set the result view to "Replace" to see the text with the matches replaced. The replacement can use these:
| Written as | Inserts |
|---|---|
$1, $2 … | What the first, second and so on group (brackets) matched |
$<name> | What the named group (?<name>…) matched |
$& | The whole match |
$$ | A $ sign |
\n, \t | A line break and a tab (this tool adds these; in a JavaScript program, \n in a string literal is already a line break) |
Without the g flag, only the first match is replaced.
Patterns that take too long
Written a certain way, a regular expression can take an extremely long time on text that doesn't match. The classic case is a repetition inside another repetition.
- Patterns like
(a+)+$,([a-zA-Z]+)*$and(a|aa)+$. - Run
(a+)+$against aaaaX, and there are 16 paths to try. With 16 a's (aaaaaaaaaaaaaaaaX), there are 65,536. Every extra a doubles it.
This tool runs the matching separately from the page and stops it if it hasn't finished after 2 seconds. Using a pattern that gets stopped here somewhere users can type freely (such as an input check) can bring a service down. Rewrite it so the repetitions don't nest.
Using it with other tools
Regular expressions differ a little between languages and tools. This tool checks with the browser's JavaScript regular expressions. If you'll use a pattern elsewhere, test it there too.
- The HTML pattern attribute: checks whether the whole value of the input matches, as if the pattern started with ^(?: and ended with )$. Write it without the / slashes. Modern browsers compile it with the v flag.
- Google Sheets (REGEXMATCH and the like): uses RE2, a different kind of regular expression. Lookahead
(?=…), lookbehind(?<=…)and\1(the same text a previous group matched) aren't available. \s matches only half-width spaces, tabs and the like, not the full-width space.
FAQ
- Is my test text sent anywhere?
- No. Matching happens only in the browser you have this page open in, and the test text isn't saved in your browser either. "Link to share" holds only the pattern, the flags and the replacement.
- A line that should match isn't highlighted.
- There are three usual causes: full-width versus half-width characters (digits, hyphens and spaces), spaces at the end of the line, and a missing m flag. In "How to read this pattern", check whether ^ and $ say "a line" or "the text".
- It looks like a hyphen, but it doesn't match.
- Several characters look like a hyphen. The full-width hyphen, the Japanese long-vowel mark and the dash are all different characters from the half-width -. Converting to half-width before the check is the reliable fix.
- Does the email example judge every address correctly?
- It only checks the shape. Whether mail actually reaches an address, you only find out by sending some. The example follows the same idea as the browser's email input field (type="email").
- Is there a limit on the test text?
- Up to 300,000 characters are checked, and up to 5,000 matches are shown.
- Can I check Python or PHP regular expressions here too?
- The basics (\d, [ ], *, +, ( ) and so on) are the same in most languages, but the details differ. Whether \d and \s match full-width characters, for example, depends on the language and its settings. Always test in the language you'll use.
Sources
- Japan Post, "Postcode and barcode manual" (in Japanese; postcodes are 7 digits, with a hyphen between the third and fourth)
- Ministry of Internal Affairs and Communications, "Q&A on telephone numbers" (in Japanese; how landline numbers are built, and how many digits they have)
- Ministry of Internal Affairs and Communications, "Telecommunications numbering system" (in Japanese; the shapes of mobile, IP phone and 0AB0 numbers)
- Ministry of Internal Affairs and Communications, "Adding 060 numbers for mobile phones" (in Japanese; from December 20, 2024, 11-digit numbers starting with 060 can be assigned to mobile phones)
- National Tax Agency, "Overview of the qualified invoice system" (in Japanese, PDF; the shape of registration numbers)
- MDN, "Character class escape: \d, \D, \w, \W, \s, \S" (\d is [0-9], \w is letters, digits and _, and \s is white space and line terminators)
- MDN, "Lexical grammar" (the characters treated as white space, including those in Unicode's Space_Separator category)
- MDN, "RegExp" (what the flags mean)
- MDN, "String.prototype.replace()" ($1, $&, $$ and $<name> in the replacement, and the g flag and how many matches are replaced)
- MDN, "<input type="email">" (a regular expression that works the same as the browser's email address check)
- MDN, "HTML attribute: pattern" (it matches the whole value, it's written without slashes, and it's compiled with the v flag)
- Google Docs Editors Help, "REGEXMATCH" (Google products use RE2)
- RE2, "Syntax" (no lookahead, lookbehind or \1, and \d, \w and \s match only ASCII characters)
- OWASP, "Regular expression Denial of Service - ReDoS" (the shapes of slow patterns, an example, and the number of paths)
All checked on November 28, 2026. Every example pattern has been tested against its matching and non-matching examples.