Sorry if this has been asked before, but I couldn\'t find any answers on the web. I\'m having a hard time figuring out the inverse to this regex:
\"\
If you always have one such link in a string, try this:
"(^[^\"]*\")|(\"[^\"]*)$"
You do not have to use replaceAll
. Better use pattern groups like the following:
Pattern p = Pattern.compile("href=\"(.*?)\"");
Matcher m = p.matcher(html);
String url = null;
if (m.find()) {
url = m.group(1); // this variable should contain the link URL
}
If you have several links into your HTML perform m.find()
in loop.
you can checkout http://regexlib.com/ for all the regex help you need. And the one below is for url :
^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$