Extract URL from HTML text
807591Apr 1 2008 — edited Apr 2 2008Suppose you have the following String that is body text with HTML.
String bodyText = " My name is Blake. I live in New York City. See my image here: <img href="http://www.blake.com/blake.jpg"/> isn't my picture awesome? Tata for now!"
I want to extract the URL that contains the location of the image in this bodyText. The ideal would be to create a function called public String extractor(String bodyText) to be used
String imageURL = extractor(bodyText);
//imageURL should be "http://www.blake.com/blake.jpg"
My first thoughts are using reg exp, yet the place i would find to use that would using the .replace in String class. I am by no means an expert on reg exp so I haven't taken too much time to try to figure it out with reg exp. I obviously could do a linear search of the bodyText and do a ton of if statements, but thats just poor coding. I want see if anyone came across this or has insight to this problem.
Thanks for all the help,
Blake