jQueryt Search for Text in a Variable?

Posted by thatryan on Stack Overflow See other posts from Stack Overflow or by thatryan
Published on 2011-01-03T02:07:19Z Indexed on 2011/01/03 3:54 UTC
Read the original article Hit count: 239

Filed under:
|

I have a variable that contains some text, some html, basically can be a string. I need to search the variable for a specific string to process that variable differently if it is contained. Here is a snippet of what I am trying to do, does not work obviously :)

$.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...

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery