Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Regex for Japanese
Regex for matching ALL Japanese common & uncommon Kanji (4e00 – 9fcf) ~ The Big Kahuna!
([一-龯])
Regex for matching Hirgana or Katakana
([ぁ-んァ-ン])
Regex for matching Non-Hirgana or Non-Katakana
([^ぁ-んァ-ン])
Regex for matching Hirgana or Katakana or basic punctuation (、。’)
([ぁ-んァ-ン\w])
Regex for matching Hirgana or Katakana and random other characters
([ぁ-んァ-ン!:/])
Regex for matching Hirgana
([ぁ-ん])
Regex for matching full-width Katakana (zenkaku 全角)
([ァ-ン])
Regex for matching half-width Katakana (hankaku 半角)
([ァ-ン゙゚])
Regex for matching full-width Numbers (zenkaku 全角)
([0-9])
Regex for matching full-width Letters (zenkaku 全角)
([A-z])
Regex for matching Hiragana codespace characters (includes non phonetic characters)
([ぁ-ゞ])
Regex for matching full-width (zenkaku) Katakana codespace characters (includes non phonetic characters)
([ァ-ヶ])
Regex for matching half-width (hankaku) Katakana codespace characters (this is an old character set so the order is inconsistent with the hiragana)
([ヲ-゚])
Regex for matching Japanese Post Codes
/^¥d{3}¥-¥d{4}$/
/^¥d{3}-¥d{4}$|^¥d{3}-¥d{2}$|^¥d{3}$/
Regex for matching Japanese mobile phone numbers (keitai bangou)
/^¥d{3}-¥d{4}-¥d{4}$|^¥d{11}$/
/^0¥d0-¥d{4}-¥d{4}$/
Regex for matching Japanese fixed line phone numbers
/^[0-9-]{6,9}$|^[0-9-]{12}$/
/^¥d{1,4}-¥d{4}$|^¥d{2,5}-¥d{1,4}-¥d{4}$/
@cb372
Copy link

cb372 commented Jul 18, 2014

Actually the regexes for hiragana and katakana are too restrictive. e.g. the katakana regex would not match words containing the 長音符, such as ユーザー and コンピューター.

Here are some more comprehensive regexes for hiragana and katakana:

Hiragana = [ぁ-ゔゞ゛゜ー]  // 0x3041-0x3094, 0x309E, 0x309B, 0x309C, 0x30FC
Katakana = [ァ-・ヽヾ゛゜ー]  // 0x30A1-0x30FB, 0x30FD, &#x30FE, 0x309B, 0x309C, 0x30FC
Hiragana or katakana = [ぁ-ゔゞァ-・ヽヾ゛゜ー]  // 0x3041-0x3094, 0x309E, 0x30A1-0x30FB, 0x30FD, &#x30FE, 0x309B, 0x309C, 0x30FC

Note that the last 3 chars in each set (0x309B, 0x309C, 0x30FC) are shared between hiragana and katakana).

@minhloc2011
Copy link

Just updated full-width Katakana from「30A1」~「30FE」 (Unicode:30FB).

Regex for matching full-width Katakana (zenkaku 全角)
([ァ-ン])

Replace to:

([ァ-ヾ])

@DevendraRxlogix
Copy link

DevendraRxlogix commented Aug 17, 2021

reg for combination of hiragana, katakana, number?

@golddranks
Copy link

Warning (this happened to myself): if you remember the range of kanji by heart ("ichi (一) kara masakari (鉞) made"), you'll get it wrong. The kanji here is not the "common" masakari 鉞 but an uncommon variant 龯, so copy-paste it to get it right!

@epistularum
Copy link

epistularum commented Sep 26, 2022

This doesn't cover all kanjis. Simple example: 𧓈

@Araxeus
Copy link

Araxeus commented Mar 18, 2023

There is a much easier way to do this:

/\p{Script=Han}|\p{Script=Katakana}|\p{Script=Hiragana}/u

see https://www.regular-expressions.info/unicode.html #Unicode Scripts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment