2

我找到了这个 java 正则表达式,但不明白它匹配什么?

Pattern.compile("\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*(\\.\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)*");

javaJavaIdentifierStart搭配什么?

4

3 回答 3

3

\\p{javaJavaIdentifierStart}表示可以作为任何有效 java 标识符的第一个字符的字符。

\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*\\.\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*表示anyIdentifier.anyIdentifier- 两个 java 标识符,用点分隔(命名空间名和类名,类名和静态成员名,对象名和成员名等)

完整(更正)正则表达式意味着(可能是合格的)java标识符 - 简单的“名称”或“名称”链,用点分隔。不过,它不一定是完全限定的名称。

于 2013-10-29T13:19:06.000 回答
2

我相信从 Java 的 Character 类调用这个方法是等价的:

isJavaIdentifierStart

public static boolean isJavaIdentifierStart(char ch)
Determines if the specified character is permissible as the first character in a Java identifier.
A character may start a Java identifier if and only if one of the following conditions is true:

isLetter(ch) returns true
getType(ch) returns LETTER_NUMBER
ch is a currency symbol (such as "$")
ch is a connecting punctuation character (such as "_").
Note: This method cannot handle supplementary characters. To support all Unicode characters,     including supplementary characters, use the isJavaIdentifierStart(int) method.

Parameters:
ch - the character to be tested.
Returns:
true if the character may start a Java identifier; false otherwise.

来源(更具可读性)

于 2013-10-29T13:18:31.310 回答
1

我相信这将匹配一个完全限定的类名。

于 2013-10-29T13:20:26.243 回答