gpt4 book ai didi

javascript - 在 javascript 上搜索文本

转载 作者:行者123 更新时间:2023-11-30 13:27:44 25 4
gpt4 key购买 nike

如何在 javascript 上搜索文本。

var v=20;
str = "The rain 20 in SPAIN stays mainly in the plain";
var patt1=/ain v/gi;
var n = str.match(patt1);
alert(n);

我正在尝试,但没有得到任何结果。我哪里错了,请哪位大哥帮帮我。

最佳答案

var v = 20; // Variable part of search query
var str = "The rain 20 in SPAIN stays mainly in the plain"; // String to search
var n = str.match('ain ' + v); // The searching, returns null if not found or the matches found. Notice the 'ain' string has been added (this can of course be changed)

if(n != null){ // if not null
alert(n + ' found!');
}else{ // if null
alert(v + ' not found...');
}

我认为这会对您有所帮助:http://jsfiddle.net/xFeAH/

关于javascript - 在 javascript 上搜索文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7893096/

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