4 releases (2 breaking)

0.3.0 Nov 16, 2022
0.2.0 Nov 24, 2020
0.1.1 Sep 24, 2019
0.1.0 Sep 24, 2019

#444 in Text processing

Download history 892/week @ 2022-12-08 644/week @ 2022-12-15 699/week @ 2022-12-22 529/week @ 2022-12-29 715/week @ 2023-01-05 773/week @ 2023-01-12 812/week @ 2023-01-19 762/week @ 2023-01-26 725/week @ 2023-02-02 690/week @ 2023-02-09 686/week @ 2023-02-16 816/week @ 2023-02-23 830/week @ 2023-03-02 1026/week @ 2023-03-09 646/week @ 2023-03-16 687/week @ 2023-03-23

3,273 downloads per month
Used in 2 crates

MIT license

406 lines


This is a simple profanity filter library for Rust.

For more information, check out the documentation.


This crate implements a simple but powerful profanity filter.

While this filter can still be technically subverted, the goal is that by the time a profanity gets past the filter, it barely resembles the original word. This is done by subverting common profanity filter workarounds, such as inserting spaces or special characters in between letters (F_U_C_K) or using similar-looking characters in the place of others (SH!T).

Keep in mind though, that this filter is far from perfect. If people really want to swear, they can get through this filter.


The [Censor] enum is the main object used for censoring strings. It is essentially a set of words to be filtered out. The [Standard] variant contains words that most people consider to be swear words, and is meant to be a good baseline for a filter. More sets and individual words can be added with the + and += operators, and sets and words can be removed with the - and -= operators.

use censor::*;

let censor = Censor::Standard;

// Use `Censor::check` to check if a string contains a profanity
assert!(censor.check("F_u c_K"));

assert!(!censor.check("fluff truck"));

// Use `Censor::censor` to censor a string with asterisks
assert_eq!("*_*_*_*_*", censor.censor("₱_û_$_$_¥"));
assert_eq!("**** that ****, dude", censor.censor("fuck that shit, dude"));
assert_eq!("******* yoouuu", censor.censor("fuuuuck yoouuu"));

// Use `Censor::replace` to replace censored words with any grawlix string
assert_eq!("What the !@#$?", censor.replace("What the fuck?", "!@#$%"));

// You can combine `Censor`s and add your own words
let censor = Standard + Zealous + Sex + "dong";

"Woops, I dropped my monster ******, that I use for my magnum ****",
censor.censor("Woops, I dropped my monster condom, that I use for my magnum dong")

// You can remove words from `Censor`s too
let censor = Standard - "ass";
assert!(!censor.check("I don't care if people say 'ass'"));

// Overlapping censored words are fully censored
let censor = Standard + Sex;
assert_eq!("**********", censor.censor("shititties"));
assert_eq!("*************", censor.censor("blowjoboobies"))