Reputation: 1167
Hello guys I have difficulties in parsing url code for example:
"http://stackoverflow.com/questions/3984422/parsing-a-list-into-a-url-string"
to:
"stackoverflow questions 3984422 parsing a list into url string"
and also in some cases the links is shows like this :
by using the below code it shows the out put is :
"www.rgagnon.com javadetails java 0614.html"
any suggestion how to add more filter?
thanks for helping.
Upvotes: 0
Views: 718
Reputation: 37051
another option:
import java.net.*;
public class GetURLName
{
public static void main(String args[]) {
try{
String urlAddress = "http://stackoverflow.com/questions/3984422/parsing-a-list-into-a-url-string";
URL url = new URL(urlAddress);
System.out.print(url.getHost().replaceAll("[/.]|http:|www|com", " ").trim()+" ");
System.out.println(url.getPath().replaceAll("[/.-]|html", " ").trim());
}
catch (Exception e){
System.out.println("Exception caught ="+e.getMessage());
}
} }
will give you this output
stackoverflow questions 3984422 parsing a list into a url string
Upvotes: 1
Reputation: 7924
How about
String url = "http://stackoverflow.com/questions/3984422/parsing-a-list-into-a-url-string";
String plain = url.replaceAll("[/-]|http:|\\.com", " ").trim();
Upvotes: 4