Unicode数字的字符类 [英] Character class for Unicode digits

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

问题描述

我需要创建一个 Pattern ,它将匹配所有Unicode数字和字母字符。到目前为止,我有\\\\ {IsAlphabetic} | [0-9]

I need to create a Pattern that will match all Unicode digits and alphabetic characters. So far I have "\\p{IsAlphabetic}|[0-9]".

第一部分对我来说效果很好,它在将非拉丁字符识别为字母字符方面做得很好。问题是下半场。显然它只适用于阿拉伯数字。字符类 \\\\ \p {Digit} 也只是 [0-9] Pattern 的javadoc似乎没有提到Unicode数字的字符类。有没有人有这个问题的好解决方案?

The first part is working well for me, it's doing a good job of identifying non-Latin characters as alphabetic characters. The problem is the second half. Obviously it will only work for Arabic Numerals. The character classes \\d and \p{Digit} are also just [0-9]. The javadoc for Pattern does not seem to mention a character class for Unicode digits. Does anyone have a good solution for this problem?

为了我的目的,我会接受一种方法来匹配字符的所有字符集.isDigit 返回 true

For my purposes, I would accept a way to match the set of all characters for which Character.isDigit returns true.

推荐答案

引用 Java docs isDigit


如果字符是一般类别类型,则字符是数字,由getType(codePoint)提供,是DECIMAL_DIGIT_NUMBER。

A character is a digit if its general category type, provided by getType(codePoint), is DECIMAL_DIGIT_NUMBER.

所以,我认为匹配数字的模式应该是 \p {Nd}

So, I believe the pattern to match digits should be \p{Nd}.

这是ideone上的工作示例。如您所见, Pattern.matches Character.isDigit 之间的结果是一致的。

Here's a working example at ideone. As you can see, the results are consistent between Pattern.matches and Character.isDigit.

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

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