Regex to remove blacklisted words from a sentence

前端 未结 3 1200
野趣味
野趣味 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

    Simple, and this works:

    String badStrRegex = "\\WBill Joseph\\W?";
    Pattern pattern = Pattern.compile(badStrRegex);
    Matcher m = pattern.matcher(testStr);  //testStr is your string under test
    boolean isBad = m.find();
    

    It works!! Tested against all your input.

提交回复
热议问题