Reputation: 1194
I'm trying to create a simple rss reader for Android and it's basically working. The problem is that in order to display the article's content, i use the <description>
tag from the rss. It appears ok, but there is an <img>
tag that usually goes off screen because it is bigger.
I used getSettings()
to resize it to fit the screen but that takes a toll to the text's size
too.
So i want to extract the text and the img tag from the description and store them to two different strings in order to be able to format them easier. I tried using regular expressions and some java methods that I found but couldn't make it work.
The description tag is formed in this way:
<p style="text-align: justify;"><img src="http://url" alt="something here" style="display: block; margin-left: auto; margin-right: auto;" />a block of text goes here</p>
So i want two strings:
str1 = <p style="text-align: justify;">a block of text goes here</p>
str2 = <img src="http://url" alt="something here" style="display: block; margin-left: auto; margin-right: auto;" />
What would be the best way to do it?
Upvotes: 2
Views: 73
Reputation: 135992
try this
String s1 = s.replaceAll(".+(<img.+?/>).+", "$1");
String s2 = s.replaceAll("(.+)<img.+?/>(.+)", "$1$2");
Upvotes: 2