badwords icon indicating copy to clipboard operation
badwords copied to clipboard

Improve split regrex

Open Hashen110 opened this issue 4 years ago • 2 comments

Add support to clean words with character _

before: console.log(filter.clean("Don't be an ash0le_word")); //Don't be an ash0le_word

after: console.log(filter.clean("Don't be an ash0le_word")); //Don't be an ******word

Hashen110 avatar Oct 26 '21 08:10 Hashen110

Unfortunately, this breaks when you have something like this:

clean("_a_s_s_h_o_l_e_")
// "_asshole"

TripleFun-Damian avatar Jan 26 '22 16:01 TripleFun-Damian

Thinking more about it, I'm not sure it's possible to have a "correct" rule in this case. In some cases, we want the _ character treated as a word break, while in others we want it treated as if it didn't exist. Once you start getting into phrases that combine the two, all bets are off

TripleFun-Damian avatar Jan 27 '22 10:01 TripleFun-Damian

the easiest way I think would be to omit all symbols. word.replace(/[^a-zA-Z]/g, "")

ghost avatar Dec 29 '22 20:12 ghost