这个正则表达式意味着什么?

时间:2013-10-29 13:10:16

标签: java regex

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

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

javaJavaIdentifierStart匹配什么?

3 个答案:

答案 0 :(得分: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.

Source(更具可读性)

答案 1 :(得分:1)

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

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

完整(更正)的正则表达式(可能是合格的)java标识符 - 简单的“名称”或“名称”链,用点分隔。但它不是必须成为一个完全合格的名字。

答案 2 :(得分:1)

这符合我认为的完全限定的类名。