从字符串中删除图像元素 [英] Remove image elements from string
问题描述
我有一个字符串,其中包含存储在var中的HTML图像元素。
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.
我试过: var content = content.replace(/< img。+> /,);
和: var content = content.find(img)。remove();
但没有运气。
任何人都可以帮助我吗?
Can anyone help me out at all?
谢谢
推荐答案
var content = content.replace(/<img[^>]*>/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
最后意味着替换所有出现(默认情况下,它只删除第一次出现)。
/g
at the end means replace all occurrences (by default, it only removes the first occurrence).
这篇关于从字符串中删除图像元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!