how html tags are extracted using java?

how html tags are extracted using java?

I would like to need the java code for extracting html tags.

View Answers

August 28, 2012 at 4:27 PM

Here is a java example that extract a tag from a line of HTML using the Pattern and Matcher classes.

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ExtractContentFromHTMLTag
{
  public static void main(String[] args)
  {
    String stringToSearch = "<p>Hello <h1>Welcome To Roseindia</h1> ...</p>";

    Pattern p = Pattern.compile("<h1>(\\S+)</h1>");
    Matcher m = p.matcher(stringToSearch);

    if (m.find()){
      String codeGroup = m.group(1);
      System.out.format("'%s'\n", codeGroup);
    }
  }
}

August 28, 2012 at 4:33 PM

Modify the above code.

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ExtractContentFromHTMLTag
{
  public static void main(String[] args)
  {
    String stringToSearch = "<p>Hello <h1>WelcomeToRoseindia</h1> ..</p>";

    Pattern p = Pattern.compile("<h1>(\\S+)</h1>");
    Matcher m = p.matcher(stringToSearch);

    if (m.find())
    {
      String codeGroup = m.group(1);

      System.out.format("'%s'\n", codeGroup);
    }

  }
}









Related Tutorials/Questions & Answers:
how html tags are extracted using java?
how html tags are extracted using java?
Advertisements
difference between java5 and java6 - Java Beginners
html tags
Java2
how to remove tags in HTML without functionalities? - Java Beginners
about java1
Using Core Tags, Html Tags
how to print HTML using javascript or Jquery
How to store extracted values from xml in a database? - XML
How to store extracted values from xml in a database? - XML
javaa swings - IDE Questions
how to write a jsp form using html
how to insert data in database using html+jsp
Javah
struts html tags - Struts
ModuleNotFoundError: No module named 'djangocms-html-tags'
ModuleNotFoundError: No module named 'lektor-strip-html-tags'
ModuleNotFoundError: No module named 'djangocms-html-tags'
How to export data from html to excel sheet by using java
how to validate the telephone number without using jquery in html with javascript
Version of commons-jelly-tags-html>commons-jelly-tags-html dependency
How to export data from html file to excel sheet by using java
How to export data from html file to excel sheet by using java
how to convert doc file into html using java swing
how to update values of a html form into an excel table using java servlets?
how to load values of html form into an excel table using java servlet?
How to give value for select in HTML dynamically using javascript
About Java2
Artifacts of commons-jelly-tags-html
Style Tags Used in HTML
How to populate an HTML table using jstl code - Spring
How you can escape a String for HTML using the StringEscapeUtils
How to Validate dynamically created text box in HTML using Javascript
Error in using jstl tags
how to save html form data into .csv file using only jsp.
How to pass and catch HTML parameters to a Java program using REST services?(without using servlet/jsp)
Maven Dependency commons-jelly-tags-html >> 20040902.072530
Version of beehive>beehive-netui-tags-html dependency
Version of controlhaus>beehive-netui-tags-html dependency
Javap Tool application
JSF HTML Tag Reference
Maven dependency for beehive - beehive-netui-tags-html version 1.0-alpha is released. Learn to use beehive-netui-tags-html version 1.0-alpha in Maven based Java projects
How to play FLV video files on Ipad using HTML code or javascript code?
how to retrieve image from mysql database using java and show it in HTML img tag ?
Version of commons-jelly>commons-jelly-tags-html dependency
using xml and html in xcode project
Maven dependency for com.gooddata - gooddata-http-client version 1.0.0+java7 is released. Learn to use gooddata-http-client version 1.0.0+java7 in Maven based Java projects
Hi how to transfer table data from html page to excel sheet by using javascript .
javas - JSP-Servlet

Ads