Java regex to strip out XML tags, but not tag contents

前端 未结 6 1573
有刺的猬
有刺的猬 2021-02-08 13:37

I have the following Java code:

str = str.replaceAll(\"<.*?>.*?|<.*?/>\", \"\");

This turns a String like so:



        
6条回答
  •  无人及你
    2021-02-08 14:01

    This isn't elegant, but it is easy to follow. The below code removes the start and end XML tags if they are present in a line together

    "www.xml.com"<\url> , "This is xml"<\body>

    Regex :

    to_replace='<\w*>|<\/\w*>',value="" 
    

提交回复
热议问题