Javascript 在NodeJs中搜索字符串时需要解决方案

Javascript 在NodeJs中搜索字符串时需要解决方案,javascript,node.js,Javascript,Node.js,我有一个字符串“platform:17.01.02”,我想通过变量搜索“17.01.02” a = "platform:17.01.02" b = "17.01.02" (has to taken from user) a.search(/b/) 上面的语句搜索“b”,而不是变量值“b”。有人能帮我搜索吗?试试这个: var a=“平台:17.01.02”; var b=“17.01.02”; log(a.search(newregexp(b))//9b看起来不像正则表达式,所以您不应该使

我有一个字符串
“platform:17.01.02”
,我想通过变量搜索
“17.01.02”

a = "platform:17.01.02"
b = "17.01.02" (has to taken from user)

a.search(/b/)
上面的语句搜索“b”,而不是变量值“b”。有人能帮我搜索吗?

试试这个:

var a=“平台:17.01.02”;
var b=“17.01.02”;

log(a.search(newregexp(b))//9
b
看起来不像正则表达式,所以您不应该使用
search
a.search(b)
在这里就足够了。search(b)对我有用。当用户意外地键入正则表达式元字符时,这将产生意外的结果