Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8997345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:52:37+00:00 2026-06-15T23:52:37+00:00

I have a string which contains some HTML code. I would like to find

  • 0

I have a string which contains some HTML code. I would like to find out if the HTML code represents visible text or an image. I used Java to solve this problem using the following regular expressions (I know you cannot parse HTML using RegExps, but I thought for what I am up to RegExps are enough).

public static String regex_html_tags_1 = "<\\s*br\\s*[/]?>";
public static String regex_html_tags_2 = "<\\s*([a-zA-Z0-9]+)\\s*([^=/>]+\\s*=\\s*[^/>]+\\s*)*\\s*/>"; 
public static String regex_html_tags_3 = "<\\s*([a-zA-Z0-9]+)\\s*([^=>]+\\s*=\\s*[^>]+\\s*)*\\s*>\\s*</\\s*\\1\\s*>"; 

public static String[] HTMLWhiteSpaces = {"&nbsp;", "&#160;"};

The code using these RegExps works fine for strings like

<h2></h2>

or alike. But a string

<img src="someImage.png"></img>

is also thought of as being empty.

Does anyone have a better idea than using RegExps to find out if some HTML code actually represents human readable text when it is interpreted by a browser? Or do you think my approach eventually leads to success?

Thanks a lot in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:52:38+00:00Added an answer on June 15, 2026 at 11:52 pm

    Try using JSoup. It let’s you parse HTML documents using css selectors (jquery-style).

    A very simple example to select all non-empty elements would be:

    Document doc = Jsoup.connect("http://my.awesome.site.com").get();
    Elements nonEmpties = doc.select(":not(:empty)");    
    

    The full-blown solution will of course require some extra work to do, like

    • iterating over lists of elements,
    • checking css styles (for display or visibility or sizes or overlaying elements)
    • checking src attributes for images
    • etc

    but it’s definitely worth it. You’ll learn a new framework, discover possibilities to ‘hide’ content in HTML / CSS and – most important – stop using regular expressions for HTML parsing 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string which contains a series of bits (like 01100011) and some
I have a list which contains some items of type string. List<string> lstOriginal; I
I have a string which contains binary data ( non-text data ). How do
I'm pretty new to PHP and have a String which contains an HTML page.
I have somebody elses code (C# ASP.Net) which contains the following query: string query
Here is the deal. I have a string which contains a html <a><img /></a>
I am extracting some text from html which is passed as a string. The
I have code like this string pattern = <(.|\n)+?>; System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Reg(pattern);
I have the following code to send users a verification email, which contains some
I have a string which contains only numbers. Now I want to remove all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.