0

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!

EDIT:

For anyone that reads this, I have figured out how to get my keywords into an array:

$("[id^='editableContent-']").filter(function() {
    var keys = $(this).html().match(/\%(.*?)\%/gi).toString();
    var keys_arr = keys.split(',');
    alert(keys_arr[1]);
});
Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412
  • dupe http://stackoverflow.com/questions/190253/jquery-selector-regular-expressions http://stackoverflow.com/questions/345194/regular-expression-matching-in-jquery – N 1.1 Mar 08 '10 at 06:03

1 Answers1

1

For anyone that reads this, I have figured out how to get my keywords into an array:

$("[id^='editableContent-']").filter(function() {
    var keys = $(this).html().match(/\%(.*?)\%/gi).toString();
    var keys_arr = keys.split(',');
    alert(keys_arr[1]);
});
Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412