我有一个包含一些文本的变量,一些html,基本上可以是一个字符串.我需要在变量中搜索特定字符串,以便在包含该变量时以不同方式处理该变量.这是我要做的事情的片段,显然不起作用:)
$.each(data.results,
function(i, results) {
var text = this.text
var pattern = new RegExp("^[SEARCHTERM]$");
if(pattern.test( text ) )
alert(text); //was hoping this would alert the SEARCHTERM if found...
Run Code Online (Sandbox Code Playgroud)