itro itro - 6 months ago 22
Java Question

How to substring a string to the second dot (.) in Java?

I have a String which has many segments separated by a dot (

.
) like this:


codes.FIFA.buf.OT.1207.2206.idu




I want to get a substring only until second dot, like
codes.FIFA
.

How to substring just until the second dot?

Answer
 Matcher m = Pattern.compile("^(.*?[.].*?)[.].*")
                    .matcher("codes.FIFA.buf.OT.1207.2206.idu");
 if (m.matches()) {
      return m.group(1);
 }

http://ideone.com/N6m8a