October 28, 2015

Some regular expressions for Japanese

regex php japanese

In working with Japanese customers, i found useful regular expressions.

Regex for matching ALL Japanese common & uncommon Kanji (4e009fcf) ~ The Big Kahuna!

1
/[-]/

Regex for matching Hirgana or Katakana 1

1
/[-んァ-]/

Regex for matching Non-Hirgana or Non-Katakana

1
/[^-んァ-]/

Regex for matching Hirgana or Katakana or basic punctuation (、。’)

1
/[-んァ-ン\w]/

Regex for matching Hirgana or Katakana and random other characters

1
/[-んァ-ン!:/]/

Regex for matching Hirgana

1
/[-]/

Regex for matching full-width Katakana (zenkaku 全角)

1
/[-]/

Regex for matching half-width Katakana (hankaku 半角)

1
/[-ン゙゚]/

Regex for matching full-width Numbers (zenkaku 全角)

1
/[-]/

Regex for matching full-width Letters (zenkaku 全角)

1
/[-]/

Regex for matching Hiragana codespace characters (includes non phonetic characters)

1
/[-]/

Regex for matching full-width (zenkaku) Katakana codespace characters (includes non phonetic characters)

1
/[-]/

Regex for matching half-width (hankaku) Katakana codespace characters (this is an old character set so the order is inconsistent with the hiragana)

1
/[-]/

Regex for matching Japanese Post Codes

1
2
/^\d{3}-\d{4}$/
/^\d{3}-\d{4}$|^\d{3}-\d{2}$|^\d{3}$/

Regex for matching Japanese mobile phone numbers (keitai bangou)

1
2
/^\d{3}-\d{4}-\d{4}$|^\d{11}$/
/^0\d0-\d{4}-\d{4}$/

Regex for matching Japanese fixed line phone numbers

1
2
/^[0-9-]{6,9}$|^[0-9-]{12}$/
/^\d{1,4}-\d{4}$|^\d{2,5}-\d{1,4}-\d{4}$/

You can try in here: http://www.regexr.com/

  1. Katakana without mentioning “full-width” or “half-width” means “full-width katakana”. 

Comments