regexp for html tags with Matlab

后端 未结 4 1837
南旧
南旧 2020-12-20 18:05

I\'m looking for a way to use regexp in order to remove all html tags from a string.
So if I have Hello&

4条回答
  •  死守一世寂寞
    2020-12-20 18:34

    It is widely accepted that using regexes to parse general html is bad form. If your html is much more complicated than the example given, then you should use an XML parser instead.

    Further discussion in this famous SO question. RegEx match open tags except XHTML self-contained tags.

    If you want to parse the content properly, then download xml_io_tools and use

    doc = xml_read('test.html')
    doc.b.FONT.CONTENT
    

    If you want to stick with regexes, then use ilya's answer, but with one of the regexes from the linked answer, e.g.,

    str = 'Hello';
    rx = '<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>';
    regexprep(str, rx, '')
    

提交回复
热议问题