removing html tags from string

前端 未结 3 1114
死守一世寂寞
死守一世寂寞 2021-01-29 07:24

I am trying to remove the HTML tags from a string. Right now I am able to remove the complete HTML tags like for example

dadsasdsad
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-29 07:44

    strippedText[i] = fragments[i]
    // full tags
    .replace(/<[^>]+>/gm, '')
    // partial tags
    .replace(/^[^>]+>/gm, '')
    .replace(/<[^>]+$/gm, '');
    

    Note that ^ has different meanings: "not" within brackets, "start" outside brackets.

    /gm should not be necessary for partial tags, but I left them as I don't know your context and how you're getting partial tags.

提交回复
热议问题