Java Regex to extract the Url of hyperlink (not to use Pattern & Matcher) (Java Regex)? -
how capture urlofhref not use pattern & matcher.
i using gwt plaform & doesn't have pattern & matcher
.
this code ok, uses pattern & matcher.
public static string gettheurlofhref(string href){ pattern p = pattern.compile("href=\"(.*?)\""); matcher m = p.matcher(href); string url = null; if (m.find()) { url = m.group(1); // variable should contain link url } return url; }
so how extract url of hyperlink (not use pattern & matcher) (java regex)?
hmm, perhaps remove don't need instead?
public static string gettheurlofhref(string href){ href = href.replaceall("^.*?href=\"", ""); // remove before // , including href=" string url = test.substring(0,test.indexof('"')); // till // first " character return url; }
i didn't put handle errors. guess add yourself.
or maybe:
public static string gettheurlofhref(string href){ string url = href.replaceall("^.*?href=\"([^\"]*)\".*", "$1"); return url; }
Comments
Post a Comment