0

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 :

'" http://www.rgagnon.com/javadetails/java-0024.html"'

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.

2
  • Which type or parsing do you need? The example is not sufficient. Commented Nov 5, 2011 at 8:18
  • any parse that will get the result into plain string without html tag Commented Nov 5, 2011 at 16:40

2 Answers 2

4

How about

String url = "http://stackoverflow.com/questions/3984422/parsing-a-list-into-a-url-string";
String plain = url.replaceAll("[/-]|http:|\\.com", " ").trim();
Sign up to request clarification or add additional context in comments.

2 Comments

Nice, but how about .com ?!
thanks it helps a lot but in some cases the links is like this : "rgagnon.com/javadetails/java-0614.html" if I use your coding the output is : www javadetails java 0614.html
1

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

4 Comments

thanks it helps a lot but in some cases the url code shown as : "[rgagnon.com/javadetails/java-0614.html]" using your code the output is "www javadetails java 0614.html" any suggestion thanks for helping "
rgagnon.com/javadetails/java-0614.html will turn into rgagnon javadetails java 0614.html , what output you wanted it to be?
i mean with http:// followed by www.rgagnon.com/javadetails/java-6.....html and I want the output to be rgagnon javadetails java 0614 without html at the back
here is how System.out.print(url.getHost().replaceAll("[/.]|http:|www|com|html", " ").trim()+" "); System.out.println(url.getPath().replaceAll("[/.-]|html", " ").trim()); , but i think you need to go to download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html and read about the replaceAll method... it will help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.