To be honest, the title is quite convoluted and difficult to explain in one sentence.
1. First of all, in order to prevent intentional people from being clever when they explode, they add punctuation marks to the vulgar language to escape the disaster. Therefore, the code adds punctuation marks in the user's words before matching with the keywords. The symbols have been removed. If the words after removing the punctuation marks match a certain keyword, it will be blacklisted. (This is not my problem...)
2. [My question is here] So how do I highlight the sentence that has not removed the punctuation marks and trigger the sentence to enter the blacklist?
example:
Why are you so stupid? ? ? I,,,fuck! ->It is related to the filter word "I rely on you", so you need to highlight the string "I,,, rely on"
淡淡烟草味2017-05-18 10:54:42
var str = '你怎么这么坑???我,,,靠!'
var keyword = '我靠'
var fourChecker = new RegExp(keyword.split('').join('[,。]*'/* 等标点符号 */), 'ig')
str = str.replace(fourChecker, function (match) {
return '<span class="four-words">' + match + '</span>'
})
console.log(str)