tags:

views:

60

answers:

1

I need a regex for following html :

<div xmlns="http://www.w3.org/1999/xhtml"&gt;    <p/>
  <p/><p/>    <p/>
</div>

This comes form a richtext field and obviously this is no meaningful content or means: empty. I can not say in java: if (richTextConent == null || richTextContent.length == 0) because the richtext field contains something. Semantically the above content is empty so i thought of using a regex. I need to match this snippet with java.util.regex

If there is something meaningful in the snippet like:

<div xmlns="http://www.w3.org/1999/xhtml"&gt; text<p/>
  <p/><p/>text    <p/>
</div>

than the regex should not match.

+3  A: 

Use a HTML parser like Jsoup.

String html1 = "<div xmlns=\"http://www.w3.org/1999/xhtml\"&gt;    <p/>  <p/><p/>    <p/></div>";
String html2 = "<div xmlns=\"http://www.w3.org/1999/xhtml\"&gt; text<p/>        <p/><p/>text    <p/>        </div>";

System.out.println(Jsoup.parse(html1).text().isEmpty()); // true
System.out.println(Jsoup.parse(html2).text().isEmpty()); // false

See also:

BalusC
Wow, i love Stackoverflow. It took only 4 minutes to get a qualified answer. I will give jsoup a try today. Thank you so far...
Masiar Ighani
You're welcome.
BalusC
Yes! That worked-Great! Many thanks BalusC
Masiar Ighani