Home > OS >  How can I use Turkish characters in Nodejs module Regex
How can I use Turkish characters in Nodejs module Regex

Time:09-21

I want use bad-words module with Turkish characters but i cant use. How can i make this?

Sample:

var Filter = require("bad-words")

var filter = new Filter({ replaceRegex:  /[A-Za-z0-9가-힣_]/g }); 
//multilingual support for word filtering

filter.addWords('ğ', 'ü', 'ı', 'i', 'e', 'y');

filter.clean("Turkish: ğ ü ı English: i e y");

output: "Turkish: ğ ü ı English: * * *"

Try it on npm RunKit: https://npm.runkit.com/bad-words

CodePudding user response:

The bad-words library does not support non-ascii letters, as it uses the ascii \b for word-boundary. Non-ascii are not even considered letters.

You can see here a proposal for a fix.

CodePudding user response:

if the RegEx engine supports Unicode then you can try to match the unicode instead of characters. see here

  • Related