問題タブ [profanity]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
regex - 単語境界の末尾にあるアスタリスク * 文字に一致 \b
検閲された冒とく的な表現の使用を検出する軽量ツールを構築する際に、単語境界の末尾にある特殊文字を検出するのが非常に難しいことに気付きました。
文字列のタプルを使用して、OR された単語境界の正規表現を作成します。
問題は、*
が単語境界の隣で検出できるものではないことです\b
。
特殊文字で終わるフレーズをサポートする便利な方法でこれを設定するためのアイデアはありますか?
javascript - Profanity Filter with ReactJS
Consider the following code:
This is supposed to be a profanity filter. The theory is that it takes input from the text area and then uses the .map() and .includes() function to compare.
swear is an array it includes some bad word.
So the map loops over the swear array, picks up each word and see if it is included in the text. If returns true it console logs (Bad word found). If not it logs(No bad word found)
The issue is that when I click the button, it logs 13 times the not required result and then logs once the required result followed by more non required result. See the image below.
What is the turnabout solution for this??