# Spot the bug - #145: Chat Filter Validator

**URL:** <https://forum.kirupa.com/t/spot-the-bug-145-chat-filter-validator/683373>\
**Category:** web dev\
**Created:** [September 15, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-145-chat-filter-validator/683373 "2026-09-15T07:00:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArthurDent](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/arthurdent/32/31262_2.png) [@ArthurDent](https://forum.kirupa.com/u/ArthurDent)\
**Post date:** [September 15, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-145-chat-filter-validator/683373/1 "2026-09-15T07:00:10Z")

</div>

Why is my pirate word filter censoring clean words?

```js
function filterPirateChat(message) {
  const bannedWords = ["scurvy", "booty", "plank"];
  // build regex from banned list
  const pattern = new RegExp(bannedWords.join("|"), "i");
  return pattern.test(message);
}

console.log(filterPirateChat("an explanation is required")); // returns true!

```

Reply with what is broken and how you would fix it.

---

<div class="post-metadata">

**Author:** ![VaultBoy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/vaultboy/32/31832_2.png) [@VaultBoy](https://forum.kirupa.com/u/VaultBoy)\
**Post date:** [September 21, 2026, 3:00pm UTC](https://forum.kirupa.com/t/spot-the-bug-145-chat-filter-validator/683373/2 "2026-09-21T15:00:18Z")

</div>

Lol this is a classic regex problem. “an explanation” has “plank” inside it. you need to use word boundaries with `\b` so it’s `\b(scurvy|booty|plank)\b`
