【问题标题】:How do I manipulate this string [duplicate]我如何操作这个字符串[重复]
【发布时间】:2020-10-18 23:54:15
【问题描述】:

我有这个挑战:

var tx =  "<p>This is a sample picture. <img src="" alt="Sample picture"> This picture is the best for the advertising...</p> ";

如何格式化这个变量来去掉img标签并得到结果:

    tx = "<p>This is a sample picture. This picture is the best for the advertising...</p> ";

【问题讨论】:

标签: javascript node.js


【解决方案1】:

您可以使用正则表达式来做到这一点。试试这个:

var tx =  "<p>This is a sample picture. <img src='' alt='Sample picture'> This picture is the best for the advertising...</p> ";

const res = tx.replace(/<img[^>]+>/, '');

console.log(res);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-13
    • 2015-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 2017-08-02
    相关资源
    最近更新 更多