Java String Comparison with html tags

I have two Strings as follow:

String input="<tr><td>Hello world</td></tr>";
String output="<body><tr><td>Hello world</td></tr></body>";

I want to compare the two strings and need to remove the <body></body> tags from the output string if the input string doesn't contain <body> tag. The string may be of any length.

How to compare and replace the output string based on input string? <body> tag may be anything like <body ></body > or < body>< /body>,etc.

Need to find the tag and replace it based on input string.


static String[] combinations = new String[] {
    "<body>","</body>","< body>","< /body>","<body >"

for (int i = 0; i < combinations.length; i++) {
    if (!input.contains(combinations[i])) {  
        output = output.replace(combinations[i], "");    

 String resultingOutput = "";
 if( !(input.contains("<body>")) && !(input.contains("</body>")) ){
      resultingOutput = output.replace("<body>", "").replace("</body>","");

Need Your Help

Watir. Select multiple radio button options

ruby watir watir-webdriver ruby-1.9.3

The issue I'm dealing with, and unable to solve due to my ignorance, is that I have a page on a browser with different education requirements which each have four radio buttons. I want to be able to

Best way to migrate from VSS to Subversion?

svn version-control visual-sourcesafe

I'm a single developer looking to get off of Visual Source Safe and move to svn.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.