Friday, September 6, 2013

how can i use regex to match this string in android?

how can i use regex to match this string in android?

I want to grab img tag from text returned from json data like that
‫#ÑÕÏ| #ÇäÞáÇÈ_3íæáíæ| Çáíæã ... ãÈäí ÇáãÑßÈÇÊ ÇáÚÓßÑí Ýí ÕáÇÍ
ÓÇáã<br /> <br /> ÊÕæíÑ ÇáãæÇØä ÇáÕÍÝí : ÚÈÏÇáÑÍãä
ÇáäÍÇÓ&#8236;<br/><br/><a
href="https://www.facebook.com/photo.php?fbid=598075296936250&amp;set=a.280183138725469.58204.103622369714881&amp;type=1&amp;relevant_count=1"
id="" title="" target="" onclick="" style=""><img class="img"
src="https://fbcdn-photos-c-a.akamaihd.net/hphotos-ak-frc3/1239478_598075296936250_1910331324_s.jpg"
alt="" /></a>
i want to grab this
<img class="img"
src="https://fbcdn-photos-c-a.akamaihd.net/hphotos-ak-frc3/1239478_598075296936250_1910331324_s.jpg"
alt="" />
what the reqular expression i must use in android to match it
I used this code but it is not working
String content = e.getString("content");
String img = "";
Pattern p = Pattern
.compile("<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>");
Matcher m = p.matcher(content);
if (m.matches()) {
Log.d("true", m.group(0).toString());
img = m.group(0).toString();
}
Log.d("image", "image : " + content);

No comments:

Post a Comment