# How to block a word with regex?

**URL:** <https://discourse.pi-hole.net/t/how-to-block-a-word-with-regex/49021>\
**Category:** Help\
**Tags:** regex\
**Created:** [August 19, 2021, 9:56am UTC](https://discourse.pi-hole.net/t/how-to-block-a-word-with-regex/49021 "2021-08-19T09:56:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SRoy](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/sroy/32/26655_2.png) [@SRoy](https://discourse.pi-hole.net/u/SRoy)\
**Post date:** [August 19, 2021, 9:56am UTC](https://discourse.pi-hole.net/t/how-to-block-a-word-with-regex/49021/1 "2021-08-19T09:56:09Z")

</div>

Let's say I wanted to block the word **magnet** , both in domain and subdomain.

So, [magnet at DuckDuckGo](https://duckduckgo.com/?q=magnet&ia=web) should be blocked, as it has the word **magnet** in it, and [https://www.magnetshop.com/](https://www.magnetshop.com/) will be blocked as well.

I tried adding magnet as a wildcard, but it didn't work. So, how would I do it?

(of course I wouldn't block the word magnet, but other niche bad words, because someone is a little too curious in my house)

---

<div class="post-metadata">

**Author:** ![jpgpi250](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/jpgpi250/32/286_2.png) [@jpgpi250](https://discourse.pi-hole.net/u/jpgpi250)\
**Post date:** [August 19, 2021, 10:04am UTC](https://discourse.pi-hole.net/t/how-to-block-a-word-with-regex/49021/2 "2021-08-19T10:04:21Z")

</div>

You can't.

In the first example, magnet isn't part of the domain. The domain is `duckduckgo.com`, no magnet in there. Pi-hole can't do anything ouside the domain, because it will never see that (not part of the query).  
Use [regex101: build, test, and debug regex](https://regex101.com/) to test your regexes.

---

<div class="post-metadata">

**Author:** ![SRoy](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/sroy/32/26655_2.png) [@SRoy](https://discourse.pi-hole.net/u/SRoy)\
**Post date:** [August 19, 2021, 10:08am UTC](https://discourse.pi-hole.net/t/how-to-block-a-word-with-regex/49021/3 "2021-08-19T10:08:17Z")

</div>

so what about the second example, can anything be done about that?

---

<div class="post-metadata">

**Author:** ![jpgpi250](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/jpgpi250/32/286_2.png) [@jpgpi250](https://discourse.pi-hole.net/u/jpgpi250)\
**Post date:** [August 19, 2021, 12:06pm UTC](https://discourse.pi-hole.net/t/how-to-block-a-word-with-regex/49021/4 "2021-08-19T12:06:53Z")

</div>

> [@SRoy](#):
>
> [https://www.magnetshop.com/](https://www.magnetshop.com/)

 ![image](https://discourse.pi-hole.net/uploads/default/original/3X/e/6/e65c2f997ea9efa064c9220c2ab64777721ea715.png)

 ![image](https://discourse.pi-hole.net/uploads/default/original/3X/9/f/9fdaedef0aa15cdcf25e6597b747a05baefe70c8.png)

---

<div class="post-metadata">

**Author:** ![DL6ER](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/dl6er/32/281_2.png) [@DL6ER](https://discourse.pi-hole.net/u/DL6ER)\
**Post date:** [August 19, 2021, 6:59pm UTC](https://discourse.pi-hole.net/t/how-to-block-a-word-with-regex/49021/6 "2021-08-19T18:59:57Z")

</div>

Even simpler:

```plaintext
magnet

```

being _exactly_ equivalent to `^.*magnet.*$`, however, much less work to be computed.

---

<div class="post-metadata">

**Author:** ![system](https://discourse.pi-hole.net/uploads/default/original/3X/7/c/7c8792f649eeb921c5d2b4c41564ffa873d9a2b8.png) [@system](https://discourse.pi-hole.net/u/system)\
**Post date:** [September 9, 2021, 7:00pm UTC](https://discourse.pi-hole.net/t/how-to-block-a-word-with-regex/49021/7 "2021-09-09T19:00:12Z")

</div>

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
