Censored Words Condition

The best solution would be to use a regex with word boundary.

if(myString.matches(".*?\\bdarn\\b.*?"))

This prevents you from matching sdarnsas a rude word. 🙂 demo here

Leave a Comment