Im implementing a profanity filter by using a Trie data structure. Every swear word is added to the Trie. When I have a string to remove profanities from, I explode the string by using punctuations and check every word with the Trie. If found I replace by asterisks.Then I implode the string The issue is, how do I keep track of punctuations? In other words how do I make sure the resultant string has punctuations?
Im implementing a profanity filter by using a Trie data structure. Every swear word
Share
If you are using
preg_split()to split up your string, consider using thePREG_SPLIT_DELIM_CAPTUREflag to capture the punctuation with the matches.Consider:
See http://php.net/preg_split for more information.