Regex to remove blacklisted words from a sentence

前端 未结 3 1187
野趣味
野趣味 2021-01-21 01:34

How can I use a regext to filter out a list of blacklisted(Obscene) words, such that if a black listed words is like \'Bill Joseph\'

 Then \'I am Bill Josephine         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-21 02:02

    Use the negation of the alphanumeric character class:

    "[^A-Za-z0-9]Bill Joseph[^A-Za-z0-9]"

    Using "\W" in place of "[^A-Za-z0-9]" would work in most cases except when there is an underscore before/after the name. So "Bill Joseph_" still would be seen as valid.

提交回复
热议问题