日文字符的正则表达式 [英] Regular Expression for Japanese characters

查看:42
本文介绍了日文字符的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Struts 进行国际化.我想为日语和英语用户编写 Javascript 验证.我知道英语的正则表达式,但不知道日语用户.是否可以为基于Unicode验证的两个用户编写一个正则表达式?

I am doing internationalization in Struts. I want to write Javascript validation for Japanese and English users. I know regular expression for English but not for Japanese users. Is it possible to write one regular expression for both the users which validate on the basis of Unicode?

请帮帮我.

推荐答案

这是一个正则表达式,可用于匹配所有英文字母数字字符、日文片假名、平假名、多字节字母数字(hankaku 和 zenkaku)和破折号:

Here is a regular expression that can be used to match all English alphanumeric characters, Japanese katakana, hiragana, multibytes of alphanumerics (hankaku and zenkaku), and dashes:

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

您可以根据需要对其进行编辑,但请注意末尾的u"标志.

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

我希望这会有所帮助!

这篇关于日文字符的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆