I have a string as follows:
This is a sample <b>String</b> I want to <div style="font-size:22px"> replace it fast </div>
How can I remove <div> start and </div> end tag from the above string in Java in one go?
You can do this:
String s = "This is a sample <b>String</b> I want to <div style=\"font-size:22px\"> replace it fast </div>";
s = s.replaceAll("[<](/)?div[^>]*[>]", "");
This will result in:
This is a sample <b>String</b> I want to replace it fast
Try the following:
myString.replaceAll("<div .*>(.*)</div>","$1");
btw: there is a online regular expression tester for java:
http://www.regexplanet.com/simple/index.html
(if you did not know it)
Hope that helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With