【发布时间】:2014-01-12 14:05:01
【问题描述】:
如何在文本字符串中查找数组项?
我不知道数组,也不知道文本。但是当文本中包含数组项时,那就派对!
var arrayString = 'apple | ape | soap',
text = "This a nice apple tree.";
var array = arrayString.split(" | ");
var matchedArrayItem = "..."; // please help on this
if(matchedArrayItem) {
$("body").append('The text contains the array item "'+ matchedArrayItem +'".');
}
【问题讨论】:
-
正则表达式应该匹配 /\b(apple|ape|tree)\b/ - 你根本不需要 jQuery