Remove image elements from string

前端 未结 8 2286
独厮守ぢ
独厮守ぢ 2021-02-20 16:47

I have a string that contains HTML image elements that is stored in a var.

I want to remove the image elements from the string.

I have tried: var content =

8条回答
  •  被撕碎了的回忆
    2021-02-20 17:43

    var content = content.replace(/]*>/g,"");
    

    [^>]* means any number of characters other than >. If you use .+ instead, if there are multiple tags the replace operation removes them all at once, including any content between them. Operations are greedy by default, meaning they use the largest possible valid match.

    /g at the end means replace all occurrences (by default, it only removes the first occurrence).

提交回复
热议问题