1

There is an html file that contains <HR size=6 color=black>

<html>
....
<HR size=6 color=black>
....
<HR size=6 color=black>
....
</html>


I want to get rid of <HR size=6 color=black>. I tried

 htmlText = htmlText.replaceAll("<(?i)hr size="+"\""+"6"+"\""+" color="+"\""+
 "black"+"\""+">", "<h1>splitLineHere</h1>");
 System.out.println(htmlText);

But this does not change anything

Donotello
  • 157
  • 2
  • 2
  • 14
  • I don't see any `"` in text you want to replace. Anyway instead of regex try using HTML parser. – Pshemo Nov 30 '13 at 15:08
  • Parsing html using regex is not a good approach. Check here: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Utku Özdemir Nov 30 '13 at 15:09

2 Answers2

4

Why are you using regex specific code? Why not simply:

htmlText .replaceAll("<HR size=6 color=black>", "<h1>splitLineHere</h1>");
WelcomeTo
  • 811
  • 8
  • 11
2

You even don't need regex. Just use replace.

String str = "<html>" +             
        "<HR size=6 color=black>" +             
        "<HR size=6 color=black>" +             
        "</html>";

System.out.println(
        str.replace("<HR size=6 color=black>", "<h1>splitLineHere</h1>")
);
Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225