Regular expression for Japanese characters

I do internationalization at Struts. I want to write Javascript confirmation for users from Japan and England. I know the regex for English, but not for Japanese users. Is it possible to write a single regular expression for users who check based on Unicode?

Please help me.

+6
source share
3 answers

This stream may be old, but just thought I was adding my 2 cents. Here is a regular expression that can be used to match all English alphanumeric characters, Japanese katakana, hiragana, multi-byte alphanumeric characters [hankaku and zenkaku], dash

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

You can edit it according to your needs, but pay attention to the “u” flag at the end.

Hope this helps!

+18
source

Provided that your text editor and programming language support Unicode, you should be able to enter Japanese characters as literal strings. Things like [AX] ranges probably won't translate well in general.

What text are you trying to check?

What language are regular expulsions in? Perl compatible, POSIX or something else?

0
source

As long as you save your scripts in the same character set as your page (for example, both HTML and JavaScript are UTF-8, or both HTML and JavaScript are Shift_JIS), you should be able to process your regular expressions in exactly the same way as and you would be in 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 
0
source

Source: https://habr.com/ru/post/893340/


All Articles