Home > Java > javaTutorial > How to remove HTML tags from given string in Java?

How to remove HTML tags from given string in Java?

PHPz
Release: 2023-08-29 18:05:06
forward
1467 people have browsed it

How to remove HTML tags from given string in Java?

String is the final class in Java, it is immutable, which means we cannot change it The object itself, but we can change the reference to the object. HTML tags can be removed from a given string using the replaceAll() method of the String class. We can use regular expressions to remove HTML tags from a given string. After removing the HTML tag from the string, it will return a string as normal text.

Syntax

public String replaceAll(String regex, String replacement)
Copy after login

Example

public class RemoveHTMLTagsTest {
   public static void main(String[] args) {
      String str = "<p><b>Welcome to Tutorials Point</b></p>";
      System.out.println("Before removing HTML Tags: " + str);
      str = str.<strong>replaceAll("\<.*?\>", "")</strong>;
      System.out.println("After removing HTML Tags: " + str);
   }
}
Copy after login

Output

Before removing HTML Tags: <p><b>Welcome to Tutorials Point</b></p>
After removing HTML Tags: Welcome to Tutorials Point
Copy after login

The above is the detailed content of How to remove HTML tags from given string in Java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template