freesozoFree tools, no sign-up (home)
All tools
Language: English
Tool number 24

Regex Tester (with Japanese Examples)

Enter a regular expression and some test text, and the matches are highlighted. You get a plain-English reading of the pattern, and can start from examples such as Japanese postcodes and phone numbers.

Flags (how to search)

Where the mistake is

    Matches

    $1 is group 1, $& is the whole match, \n is a line break and \t is a tab.

    • text Matches
    • Line with a match

      Your test text is used only on this page. It isn't sent anywhere or saved in your browser. Only the regular expression, the flags and the replacement are saved.

      How to read this pattern

        What to do next

        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

        NamePatternFlagsWhat it matches, and what to watchTry
        Japanese postcode^\d{3}-?\d{4}$gmSeven 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}\bg\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}$gmA 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}$gm11 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}$gm10 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})$gmNumbers starting with 0120 have 10 digits, and numbers starting with 0800 have 11.
        Invoice registration number^T\d{13}$gmA 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])$gmMonths 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$gmHours 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})*)$gmMatches 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}県)(.+)$gmGroup 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

        NamePatternFlagsWhat it matches, and what to watchTry
        Hiragana only^[ぁ-んー]+$gmMatches hiragana from the small a to n, plus the long-vowel mark. Spaces don't match.
        Full-width katakana only^[ァ-ヶー]+$gmMatches 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][ァ-ヶー]+)*$gmAllows a single half-width or full-width space between runs of full-width katakana. \u3000 is the full-width space.
        Find half-width katakana[ヲ-゚]+gFinds 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]+gFinds runs of full-width letters and digits.
        Find full-width spaces\u3000g\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+$gmIn 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]+$gmSymbols and spaces don't match. To allow underscores too, you can write ^\w+$.

        Web and form checks

        NamePatternFlagsWhat it matches, and what to watchTry
        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])?)*$gimFollows 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 texthttps?://[\w/:%#$&?()~.=+@,;!*'-]+gFinds 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

        NamePatternFlagsWhat it matches, and what to watchTry
        Reformat dates into the Japanese style(\d{4})[/-](\d{1,2})[/-](\d{1,2})→ $1年$2月$3日gThe parts in ( ) can be used as $1, $2 and $3 in the replacement.
        Remove HTML tags<[^>]+>→ (delete)gRemoves 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)gmRemoves 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 spacegTurns 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\ngTurns 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.

        KindRuleExample
        Postcode7 digits, with a hyphen between the third and fourth100-0001
        Landline0 + 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 all03-1234-5678
        Mobile11 digits starting with 060, 070, 080 or 090. The fourth digit isn't 0090-1234-5678
        IP phone11 digits starting with 050. The fourth digit isn't 0050-1234-5678
        0120, 0570 and similar10 digits starting in the form 0AB0. Only 0800 numbers have 110120-123-456
        Invoice registration numberT + 13 digitsT1234567890123

        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 asMatchesWhat to watch with Japanese data
        \dHalf-width 0 to 9Doesn't match full-width digits (123)
        \wHalf-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
        \sSpaces, tabs, line breaks and so on, including the characters Unicode classes as spacesMatches the full-width space too
        \bThe boundary between a character \w matches and one it doesn'tThere 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)

        FlagWhen ticked
        gFinds every match. Without it, only the first match is found.
        iTreats upper and lower case as the same letter.
        mMakes ^ and $ match at the start and end of each line, instead of the whole text. Use it to check one value per line.
        sLets . match line breaks too. Without it, . never matches a line break.
        uEnables Unicode syntax such as \p{Script=Han} (kanji), and treats characters such as emoji as one character.
        yOnly 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 asInserts
        $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, \tA 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

        All checked on November 28, 2026. Every example pattern has been tested against its matching and non-matching examples.

        More tools