What built-in regex character classes are supported Java

∥☆過路亽.° 提交于 2019-12-12 07:59:25

问题


...when used in patterns like "\\p{someCharacterClass}".
I've used/seen some:

  • Lower
  • Upper
  • InCombiningDiacriticalMarks
  • ASCII

What is the definitive list of all supported built-in character classed? Where is it documented? What are the exact meanings?

Edited...

There seem to be a lot of "RTFM" answers refering to the javadoc for Pattern. That's the first place I looked before asking this question. Just so everyone is clear, the javadoc for Pattern makes no mention of any of the classes listed above.

The "correct" answer will mention "InCombiningDiacriticalMarks" somewhere on the page, and will not be some vague reference to "Unicode Standards".


回答1:


The documentation for Pattern says in the "Unicode Support" section:

The supported categories are those of The Unicode Standard in the version specified by the Character class. The category names are those defined in the Standard, both normative and informative. The block names supported by Pattern are the valid block names accepted and defined by UnicodeBlock.forName.

The documentation for UnicodeBlock.forName states:

Block names are determined by The Unicode Standard.

On http://unicode.org there is the FAQ Where can I find the definitive list of Unicode blocks?:

A: The Unicode blocks and their names are a normative part of the Unicode Standard. The exact list is always maintained in one of the files of the Unicode Character Database, Blocks.txt.

Finally, in Blocks.txt there is the line:

0300..036F; Combining Diacritical Marks

These characters can be found in the Combining Diacritical Marks code chart (from Unicode 6.0 Character Code Charts).




回答2:


Pattern API says to adhere to regular expression level 1 as defined by http://www.unicode.org/reports/tr18/

There are three nice tables (search UCD.html), and look at UCD.html itself.




回答3:


The spec is http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html. In some cases, it refers to TUS for a particular version, you can find that material at http://unicode.org.




回答4:


This page has some good details for a few popular classes like:

  • \p{L} or \p{Letter}: any kind of letter from any language.
  • \p{M} or \p{Mark}: a character intended to be combined with another character (e.g. accents, umlauts, enclosing boxes, etc.).
  • \p{N} or \p{Number}: any kind of numeric character in any script.



回答5:


Look in the javadocs for the Pattern class.



来源:https://stackoverflow.com/questions/8650267/what-built-in-regex-character-classes-are-supported-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!