I have a phrase:
let msg = "Dear XX,Thanks for visting XX"
let usermsg = "Dear sd dta,Thanks for visting ght hg"
I need to compare these two sentences, ignoring "XX" and "YY". How can I create a regular expression to compare both of these in Nodejs?
I have replaced "XX" with an empty space and tried whether the usermsg
includes msg
or not. But that doesn't work.
var separators = ['XX','YY'];
let dMsg = msg.split(new RegExp(separators.join('|'),'g'));
for (var p = 0; p < dMsg.length; p++) {
if (!(usermsg.includes(dMsg[p]))) {
console.log("fail");
break;
}
}
It doesn't work if the user adds an extra string in front, like:
usermsg2 = "Hey Dear ghgh,Thanks for visting jkj",
In the above usermsg2
, "Hey" should not be there, but my code returns that both are the same.
Kindly suggest how to check these?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…