2

I have html like bellow

<html lang="en">
<head>
<meta http-equiv ...............
    ...................
</head> ..............
...............
</html>

I want to replace <head>.....</head> with ""(empty) and final string should look like this

<html lang="en">..............
....................
</html>

I tried with this but no luck nothing changed. any help is appreciated

 myStr= myStr.replaceAll("^<head>.*</head>$", "");

 System.out.println(myStr);
Rahul Gopi
  • 414
  • 1
  • 16
  • 31
someone
  • 6,577
  • 7
  • 37
  • 60

2 Answers2

1
<head>\\s*([\\s\\S]*?)\\s*<\\/head>

You will have to replace by $1 here.See demo.

https://regex101.com/r/uF4oY4/20

vks
  • 67,027
  • 10
  • 91
  • 124
0

Try This

String replStr  = "<head>\\s*([\\s\\S]*?)\\s*</head>";
String yourHtml = "<html> <head>   <meta http-equiv ............</head></html>";

yourHtml = yourHtml.replaceAll(replStr, "");

System.out.println("Ans :   "+yourHtml);
Rahul Ahirrao
  • 319
  • 3
  • 10