javascript - Compare the unsigned string with the keyword after removing the punctuation, highlight the keyword without removing the punctuation
阿神
阿神 2017-05-18 10:52:42
0
1
815

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"

阿神
阿神

闭关修行中......

reply all(1)
淡淡烟草味
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)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template