itro itro - 1 year ago 60
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:


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

How to substring just until the second dot?

Answer Source
 Matcher m = Pattern.compile("^(.*?[.].*?)[.].*")
 if (m.matches()) {