我试图获得一个特定单词在输入字段上的键盘上的文本字段中返回多少匹配的结果。到目前为止,如果输入与文本字段中的单词匹配,我已成功记录成功消息。有人知道如何检查文本字段中这个单词的计算次数吗?
这是我到目前为止所得到的
[{
id: '<http://www.test.com/ontologies/Author/JohnGrisham>',
firstName: 'John',
lastName: 'Grisham',
book: [
{
id: '<http://www.test.com/ontologies/Book/TheFirm>',
name: 'The Firm',
retailer: ['Amazon', 'Waterstones', 'Foyles']
},
{
id: '<http://www.test.com/ontologies/Book/TheClient>',
name: 'The Client',
retailer: ['Amazon', 'Waterstones', 'Foyles']
}
]
}]
答案 0 :(得分:0)
var keyWordNL = $('input[name*="keyword-nl_NL"]').val(); //keyword to search
var editor2 = $('#introduction-nl_NL').val(); // searched will be performed in this field
regex = new RegExp(keyWordNL,"g");
console.log((editor2.match(regex) || []).length);