gpt4 book ai didi

Javascript删除某个单词所在的html行

转载 作者:行者123 更新时间:2023-11-30 16:12:08 24 4
gpt4 key购买 nike

如何使用 javascript 删除字符串中包含特定单词的行?

word1
word2
word3

运行 javascript 代码后,我希望它看起来像这样:

word1
word3

我知道我可以使用 str.replace("word2",'') 让它看起来像这样:

word1

word3

但我似乎无法摆脱这个词所在的那一行。

谢谢!

最佳答案

您可以尝试使用正则表达式删除换行符:

    str.replace(/^(\r\n)|(\n)/,'');

替换两个绑定(bind)两个替换函数,如:

   str.replace("word2",'').replace(/^(\r\n)|(\n)/,'');

关于Javascript删除某个单词所在的html行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36084907/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com