开发者

Test if a string is a Java variable identifier: (a-z,A-Z,_,$) followed by (a-z,A-Z,0-9,_,$)

开发者 https://www.devze.com 2023-03-21 17:03 出处:网络
I need to determine if a string is a variable identifier. i.e. (a-z,A-Z,,$) followed by (a-z开发者_如何学Python,A-Z,0-9,,$)

I need to determine if a string is a variable identifier.

i.e. (a-z,A-Z,,$) followed by (a-z开发者_如何学Python,A-Z,0-9,,$)

I know I can do it with a manually configured reg exp, but there must be a more compact, built in function I can use.

Any solutions?


You can use the methods Character.isJavaIdentifierStart() and Character.isJavaIdentifierPart() but I don't think the solution will be more compact.

EDIT: I decided to search and found this in Codemodel: http://codemodel.java.net/nonav/apidocs/com/sun/codemodel/JJavaName.html

0

精彩评论

暂无评论...
验证码 换一张
取 消