Python strip XML tags from document

前端 未结 3 529
青春惊慌失措
青春惊慌失措 2020-12-19 00:44

I am trying to strip XML tags from a document using Python, a language I am a novice in. Here is my first attempt using regex, whixh was really a hope-for-the-best idea.

3条回答
  •  时光取名叫无心
    2020-12-19 01:13

    Please, note, that usually it is not normal to do it by regular expressions. See Jeremiah answer.

    Try this:

    import re
    
    text = re.sub('<[^<]+>', "", open("/path/to/file").read())
    with open("/path/to/file", "w") as f:
        f.write(text)
    

提交回复
热议问题