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]);
});
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]);
});
精彩评论