I have an html string and I am trying to replace a paragraph mark. I can do this manually in word by selecting edit > find what: ^p > replace with ^s > replace all. My question is how do I do this with an html string in python?
sample_html_string = "<html>
<title>
Hello
</title>
</html>"
correct_html_string = "<html><title>Hello</title></html>"
The issue is not simply solved using re.sub because I have a more complex html string that contains li tags and p tags, where I want to keep formatting.
You can do this way:
It’ll replace all the space characters and perfectly works for your example
If you need to replace the paragraph mark (you mean
\n, right?) you can use built-inreplace: