Results 1 to 7 of 7

Thread: [RESOLVED] Finding URLs in a String using Regular Expressions

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2007
    Location
    England
    Posts
    61

    Resolved [RESOLVED] Finding URLs in a String using Regular Expressions

    Hello.

    I am trying to write an app that will read in a HTML document and extract all the URLs from it.

    I currently have the HTML document being read in line by line and I need to be able to identify if there are any URLs in the string.

    Someone suggested using Regular Expressions?

    I am having abit of trouble doing this.

    I am trying something like this but it doesnt work. Any help will be great!! THANKS

    Code:
    		String test = new String("bla bla bla http://somesite.com/tmp/page.html bla bla");
    		String regex = "@\"http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?\\b\")";
    		Pattern p = Pattern.compile(regex);
    		Matcher m = p.matcher(test);
    		
    		if (m.find()){
    			System.out.println(m.group(1));
    		}
    		else{
    			System.out.println("Not found!");
    		}
    Last edited by DonCash; Oct 24th, 2007 at 09:58 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width