Skip to content

How it all works

Sam P. edited this page Jan 31, 2026 · 3 revisions

Basically, all this does is take in words and make a highly complex regex string to be applied to text. Not exactly complex.

Inner workings

To start, the configuration loads in all the words from the badwords.json file. After that, each word is fed into a RegEx string generator. After that's done, the strings are all fed into a megastring with groupnames as the word that they're looking for, and the megastring also includes lookahead and lookbehind. The megastring aims to catch all possible combinations that could hide any sort of word you're trying to ban. All that comes after is reading in text and applying the pattern.

RegEx string construction

Construction is easily summarized in a few steps.

Given a word, iterate the following steps over each character:

  1. Look up the letter in the equivalence table (contains things like "@" and "4" for "a") and create a letter group with all of those letters like so: [@4a]
  2. Append a "+" to the end to stop people from repeating letters to bypass
  3. Append a detector for separators directly after, like so: [\W_]*
  4. Append to a string

Note: when you compile, it's done as case insensitive

Shortcomings

In order to stop words such as "class" from being detected as "ass", I've implemented a rule in the lookahead and lookbehind that requires a separator between words to separate words that should be blocked from words that shouldn't. This DOES mean, however, that strings such as "unfuckingbelievable" will not be picked up. Moderators are still necessary, but a large weight is taken off their shoulders. Also: due to this rule, "fucking" and other words will not be picked up unless they're put into the badwords.json specifically. In this same vein, you can avoid the "unfuckingbelievable" problem by adding it to your badwords.json.

Clone this wiki locally