Alternative to successive String.replace

后端 未结 7 1076
無奈伤痛
無奈伤痛 2020-12-14 07:10

I want to replace some strings in a String input :

string=string.replace(\"

\",\"\"); string=string.replac

7条回答
  •  醉话见心
    2020-12-14 07:34

    The particular example you provide seems to be HTML or XHTML. Trying to edit HTML or XML using regular expressions is frought with problems. For the kind of editing you seem to be interested in doing you should look at using XSLT. Another possibility is to use SAX, the streaming XML parser, and have your back-end write the edited output on the fly. If the text is actually HTML, you might be better using a tolerant HTML parser, such as JSoup, to build a parsed representation of the document (like the DOM), and manipulate that before outputting it.

提交回复
热议问题