gpt4 book ai didi

javascript - 如果 JavaScript 中的特定单词匹配,则替换行

转载 作者:行者123 更新时间:2023-11-28 20:57:56 25 4
gpt4 key购买 nike

如果行中的特定单词匹配,那么我想阅读整行。我怎样才能做到这一点。

就像如果

var str = "this is test sample msg \n this is second line \n  ";

包含“sample”单词的行将被返回。

如何在 JavaScript 中执行此操作?

最佳答案

var str = "this is test sample msg \n this is second line \n third samples";
str.split("\n").filter(function(str) {
return ~str.indexOf("sample")
});
//["this is test sample msg ", " third samples"]

关于javascript - 如果 JavaScript 中的特定单词匹配,则替换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11718758/

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