Parsing result of URL.getHost()

前端 未结 2 1878
天涯浪人
天涯浪人 2021-01-19 19:16

Need help parsing...

In my code, I have a method that returns url.getHost();. But the results of that can be blarg.com, or sometimes dates.blarg.com. I want to retur

2条回答
  •  孤街浪徒
    2021-01-19 20:05

    String host = url.getHost();
    Matcher m = Pattern.compile("^.+[.]([^.]+[.][^.]+)$").matcher(host);
    if(m.matches()) {
      host = m.group(1);
    }
    

提交回复
热议问题