假设我们要检查是否speech包含特定句子 ( reference)但在它的最后和结尾:
这是reference:
let reference = "have you ever look at someone";
基于此,reference我们要比较speech并返回匹配或不匹配:
let speech = "blaaaah have you ever look at someone"; // Match because 'have you ever look at someone' is at the end of speech
let speech = "have you ever look at someone blaaaah"; // No match because something else came after 'have you ever look at someone'
问题是我无法区分上述语音示例并且代码总是返回匹配:
//let speech = "blaaaah have you ever look at someone"; // matched
let speech = "have you ever look at someone blaaaah"; // No match
let reference = "have you ever look at someone";
if(new RegExp("\\b"+reference+"\\b").test(speech)){
console.log("Finally Matched!")
} else {
console.log("No Match At Last!")
}
守着一只汪
拉风的咖菲猫
相关分类