- Create a new method in your RegExDemo class called SanitizeInput() and let it accept a string parameter:
public string SanitizeInput(string input) { }
- Add a list of type List<string> to the method that contains the bad words we want to remove from the input:
List<string> lstBad = new List<string>(new string[] { "BadWord1", "BadWord2", "BadWord3" });
In reality, you might make use of a database call to read the blacklisted words from a table in the database. You would usually not hardcode them in a list like this.
- Start constructing the regex that we will use to look for the blacklisted words. You concatenate the words with the | (OR) metacharacter so that the regex will match any of the words. When the list is ...