Regular Expression for Japanese characters

∥☆過路亽.° 提交于 2019-11-28 08:41:44

This thread may be old but just thought that I add my 2 cents. Here is a regular expression that can be used to match all English alphanumerics, Japanese katakana,hiragana,multibytes of alphanumerics [hankaku and zenkaku],dashes

/[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+|[a-zA-Z0-9]+|[a-zA-Z0-9]+[々〆〤]+/u

You can edit it to fit your needs but notice the "u" flag at the end.

I hope this helps!

Provided your text editor and programming language support Unicode, you should be able to enter Japanese characters as literal strings. Things like [A-X] ranges will probably not translate very well in general.

What kind of text are you trying to validate?

What language are the regular experssions in? Perl-compatible, POSIX, or something else?

As long as you save your scripts in the same character set as your page (e.g. both HTML and JavaScript are UTF-8 or both HTML and JavaScript are Shift_JIS), you should be able to treat your regular expressions exactly the same as you would with English.

function isKansai(city) {
    var rxKansai = /(大阪|兵庫|京都|滋賀|奈良|和歌山|osaka|hyo{1,2}go|kyoto|shiga|nara|wakayama)/i;
    return rxKansai.test(city);
}
isKansai('東京'); // false
isKansai('大阪'); // true
isKansai('Tokyo'); // false
isKansai('Osaka') // true
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!