• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

regex to pull web links in java

anyone know the regex patters to go through a string and pull all web links from <a href
and display in the form www.google.com
0
enigma1234567890
Asked:
enigma1234567890
  • 5
  • 4
  • 3
2 Solutions
 
enigma1234567890Author Commented:
i want to do it via regex
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
a_bCommented:
use Pattern.compile("href=\\\"(.*?)\\\"", Pattern.CASE_INSENSITIVE)
0
 
enigma1234567890Author Commented:
this returns stuff like href="http://google.com"  ho do i drop the href

thanks
0
 
a_bCommented:
Just get the substring of the retrurned string from position 5 to sting lenght
0
 
enigma1234567890Author Commented:
finally

is their a method to not report blank  href=""
0
 
Terry WoodsIT GuruCommented:
Modifying enigma's suggestion, try:

Pattern.compile("(?:href=\\\")([^\\\"]+?)(?:\\\")", Pattern.CASE_INSENSITIVE)
0
 
enigma1234567890Author Commented:
could you explain what is taking place for example what does the following do

?
\\\
^\\\


thanks
0
 
Terry WoodsIT GuruCommented:
(?:blah) is a non-capturing sub pattern. It means match blah but don't capture it in the result.

[^abc] means match any one character that's not a or b or c

\\\" is used to match a double quote character. I'm probably not the best person to explain how escaping backslash characters works in java, but it somehow works out that they need double-escaping! People (including me) commonly get confused with how many backslashes to use.
0
 
Terry WoodsIT GuruCommented:
You might find this cheat-sheet useful:
http://www.phpguru.org/article/pcre-cheat-sheet
0
 
enigma1234567890Author Commented:
thanks all will close the call
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now