jQuery remove tag from HTML String without RegEx

前端 未结 6 1703
情话喂你
情话喂你 2020-12-05 14:25

So I have following string:

var s = \'Some Text Some other Text\';

The result should be a string with the content

6条回答
  •  囚心锁ツ
    2020-12-05 14:41

    This may suit your needs:

    <([^ >]+)[^>]*>.*?|<[^/]+/>
    

    Regular expression visualization

    Debuggex Demo

    In JavaScript:

    $s = s.replace(/<([^ >]+)[^>]*>.*?<\/\1>|<[^\/]+\/>/ig, "");
    

    It also removes self-closing tags (e.g.
    ).

提交回复
热议问题