Using jQuery to find keywords in string

Posted by Nic Hubbard on Stack Overflow See other posts from Stack Overflow or by Nic Hubbard
Published on 2010-03-08T06:00:42Z Indexed on 2010/03/08 6:06 UTC
Read the original article Hit count: 264

In php, I have used preg_match_all() to find keywords (using the format %keyword%) in a string, which works wonderfully and returns an array of all found keywords.

What I would like to do, is do the same thing using jQuery or javascript. I have tried using the filter() function, and it kind of works. But I think I am missing something.

How can I find ALL instances of the keyword in a string, using a regex?

Here is what I have worked out so far:

$("[id^='editableContent-']").filter(function() {
    alert($(this).html().match(/\%(.*?)\%/));
});

Any suggestions are welcome!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex