java - Regular expression matching fully qualified class names -


what best way match qualified java class name in text?

examples: java.lang.reflect, java.util.arraylist, org.hibernate.hibernate.

a java qualified class name (lets "n") has structure

n.n.n.n 

the "n" part must java identifier. java identifiers cannot start number, after initial character may use combination of letters , digits, underscores or dollar signs:

([a-za-z_$][a-za-z\d_$]*\.)*[a-za-z_$][a-za-z\d_$]* ------------------------    -----------------------           n                           n 

they can not reserved word (like import, true or null). if want check plausibility only, above enough. if want check validity, must check against list of reserved words well.

java identifiers may contain unicode letter instead of "latin only". if want check well, use unicode character classes:

([\p{letter}_$][\p{letter}\p{number}_$]*\.)*[\p{letter}_$][\p{letter}\p{number}_$]* 

or, short

([\p{l}_$][\p{l}\p{n}_$]*\.)*[\p{l}_$][\p{l}\p{n}_$]* 

the java language specification, (section 3.8) has details valid identifier names.

also see answer question: java unicode variable names


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -