How to match a fully qualified class name like com.mycompany.models.Friend
using regex and strip away the package name so the result would be Friend
for the example given?
Asked
Active
Viewed 1,677 times
-1
-
Related: http://stackoverflow.com/questions/5205339/regular-expression-matching-fully-qualified-java-classes – Brian Roach Apr 23 '14 at 07:05
1 Answers
5
You can simply do:
System.out.println(s.substring(s.lastIndexOf(".") + 1));
This will print Friend

Salah
- 8,567
- 3
- 26
- 43
-
The OP want a regex to extract Friend from any fully qualified name, and this just a simple way with out using regex, and am pretty sure that this can solved the OP problem – Salah Apr 23 '14 at 07:08
-
I adjusted the question and the title to be less ambiguous. I undid my down vote. Sorry for that. – Harmlezz Apr 23 '14 at 07:13
-
-
@Harmlezz it seems that OP wants to first match full package name of class from its text and then find name of class. So your edit could oversimplify what OP really wanted. – Pshemo Apr 23 '14 at 07:16
-
-
@Harmlezz Now should be better. I suspect that all here got downvoted because initially we didn't try to find full package name of class but we assumed that it was passed as input. – Pshemo Apr 23 '14 at 07:22