get domain strings from uri in java
String uri = "http://foo.bar/spam/ham";
String domain = null;
Pattern p = Pattern
.compile("https?:\/\/[-_.!~*'()a-zA-Z0-9;?:\@&=+\$,%#]+\/");
Matcher m = p.matcher(uri);
if (m.find()) {
domain = m.group(0);
}
assertEquals("http://foo.bar/", domain);
Written by KOIZUMI teruaki
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Java
Authors
Related Tags
#java
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#