Reg expression to remove empty Tags (any of them)?

后端 未结 3 973
醉酒成梦
醉酒成梦 2020-12-18 17:21

I like to remove any empty html tag which is empty or containing spaces.

something like to get:

$string = \"text&         


        
3条回答
  •  一生所求
    2020-12-18 17:33

    You will need to run the code multiple times in order to do this only with regular expressions.

    the regex that does this is:

    /<(?:(\w+)(?: [^>]*)?`> *<\/$1>)|(?:<\w+(?: [^>]*)?\/>)/g
    

    But for example on your string you have to run it at least twice. Once it will remove the
    and the second time will remove the remaining

    .

提交回复
热议问题