-4

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?

Harmlezz
  • 7,524
  • 23
  • 34
quarks
  • 29,080
  • 65
  • 239
  • 450

1 Answers1

2

You can simply do:

System.out.println(s.substring(s.lastIndexOf(".") + 1));

This will print Friend

Salah
  • 8,098
  • 3
  • 20
  • 39
  • 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
  • I got 2 downvoted also, i don't know why, but Its Just ok. – Salah Apr 23 '14 at 07:16
  • @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
  • @Pshemo I hope I improved things now to catch both aspects. – Harmlezz Apr 23 '14 at 07:19
  • @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