i have this img tag from server. can anyone tell code to extract image link from the below tag.
>
onClick=showPresc
More fool proof using regex:
String html = "<img SRC=\"whatever\">whatever</img>"
String imgRegex = "<[iI][mM][gG][^>]+[sS][rR][cC]\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";
Pattern p = Pattern.compile(imgRegex);
Matcher m = p.matcher(html);
if (m.find()) {
String imgSrc = m.group(1);
}
This will take care of possible upper/lower case issues, which the previous solution has, and also tries to handle more unusual cases.
Something along the lines of:
int start = tags.indexOf("src=\"") + 5;
int end = tags.indexOf("\"", start);
String src = tags.substring(start, end);