Java 正则表达式中的重音符号
我想使用 Hibernate Validator 来验证一些列。据我了解,问题在于 java 中的 \w 标记不接受带有重音符号的字母。
有什么方法可以编写正则表达式,以便可以验证像 Relatório 这样的单词(我不想在括号之间写所有带有重音符号的字母,因为我希望在很多列中编写这个正则表达式)?
I'd like to use Hibernate Validator to validate some columns. The problem, as I understand, is that the \w marker in java doesn't accept letters with accents on them.
Is there any way that I could write the regexp so that words like Relatório could be validated (i wouldn't want to write all letters with accents between brackets, because I expect to be writing this regexp in a lot of columns)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java regex 文档 有一个部分Unicode 类别(搜索“Unicode 块和类别的类”)。如果您只是寻找字母,我认为
\p{L}
是您想要的类别。The Java regex documentation has a section on Unicode categories (search for "Classes for Unicode blocks and categories"). If you're just looking for letters, I think
\p{L}
is the category you want.我有更多的运气:
在java中我使用以下方法:
I had more luck with:
In java I use the following method: