2
I am trying to create a Regex that filters by certain words, to be used in the validation of the name entered by the user in a conversation with a chatbot. Since it’s about filtering out bad words, I traded them in for palavraox
, so that this question would not be offensive.
What I’ve been able to do so far is:
/^((?!palavrao1|palavrao2|palavrao3|Palavrao1|Palavrao2|Palavrao3|PALAVRAO1|PALAVRAO2|PALAVRAO3).)*$/
The problem is, if a person has the name that contains any of these bad words, they will be filtered. In this case, the name "Cuca" would not be valid for the exact reason.
So I wonder what it would be like to search for the swear word literally, not just if the name contains such bad words.
Note: I know it is possible to use the flag /i
to make Regex case-insensitive, but chatbot unfortunately does not accept these flags.
Use the Word Boundary, the famous
\b(palavra)\b
. He will make the word not part of another.– CypherPotato