# Censor specific text patterns

**URL:** https://meta.discourse.org/t/censor-specific-text-patterns/26042
**Category:** Support
**Created:** [March 5, 2015, 8:48pm UTC](https://meta.discourse.org/t/censor-specific-text-patterns/26042 "2015-03-05T20:48:59Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![optimus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/optimus/32/39715_2.png) [@optimus](https://meta.discourse.org/u/optimus)
#### Post date: [March 5, 2015, 8:48pm UTC](https://meta.discourse.org/t/censor-specific-text-patterns/26042/1 "2015-03-05T20:48:59Z")

</div>

Hi, I saw in Discourse that there is a way to censor words in admin/site\_settings/category/posting - does anyone know of a way to censor specific patterns? For example, I foresee HR people eventually using the Discourse forum and to protect them from themselves posting sensitive info I want to automatically remove SSNs (i.e. XXX-XX-XXXX). Has anyone had this need before and found a way to do it?

Please share any advice 😄

Cheers,  
Chris

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 5, 2015, 9:15pm UTC](https://meta.discourse.org/t/censor-specific-text-patterns/26042/2 "2015-03-05T21:15:41Z")

</div>

We don’t support censoring wildcards or regular expressions, would probably need to be a plugin.

---

<div class="post-metadata">

### Author: ![downey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/downey/32/166878_2.png) [@downey](https://meta.discourse.org/u/downey)
#### Post date: [March 5, 2015, 9:17pm UTC](https://meta.discourse.org/t/censor-specific-text-patterns/26042/3 "2015-03-05T21:17:40Z")

</div>

Something like this would also be useful for the inclusion of full email addresses being discussed in other topics right now and caused by HTML email parsing bugs.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 5, 2015, 9:21pm UTC](https://meta.discourse.org/t/censor-specific-text-patterns/26042/4 "2015-03-05T21:21:13Z")

</div>

This would absolutely require the work that @zogstrip is doing around hoisting out code and pre blocks in the pipeline earlier.

---

<div class="post-metadata">

### Author: ![optimus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/optimus/32/39715_2.png) [@optimus](https://meta.discourse.org/u/optimus)
#### Post date: [March 5, 2015, 10:24pm UTC](https://meta.discourse.org/t/censor-specific-text-patterns/26042/5 "2015-03-05T22:24:50Z")

</div>

Thanks Jeff. If @zogstrip needs help testing at any point I would be happy to help 😄.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [March 9, 2015, 3:38pm UTC](https://meta.discourse.org/t/censor-specific-text-patterns/26042/6 "2015-03-09T15:38:46Z")

</div>

How is it related to the hoisting of code blocks?

---

<div class="post-metadata">

### Author: ![optimus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/optimus/32/39715_2.png) [@optimus](https://meta.discourse.org/u/optimus)
#### Post date: [March 9, 2015, 3:59pm UTC](https://meta.discourse.org/t/censor-specific-text-patterns/26042/7 "2015-03-09T15:59:45Z")

</div>

Honestly, not sure…just asked about censoring text patterns. Jeff mentioned you were working on something related, maybe he can clarify ☺?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 9, 2015, 4:05pm UTC](https://meta.discourse.org/t/censor-specific-text-patterns/26042/8 "2015-03-09T16:05:25Z")

</div>

The regex to block, say, a phone number pattern, would match inside pre and code blocks unless they were hoisted out very early in the pipeline.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [March 9, 2015, 4:08pm UTC](https://meta.discourse.org/t/censor-specific-text-patterns/26042/9 "2015-03-09T16:08:20Z")

</div>

Ok, so now that it’s done, @optimus, you’ll need to write a plugin 😉

Something like (not tested)

```javascript
Discourse.Dialect.addPreProcessor(function(text) {
   return text.replace(/your-regexp/g, "your replacement");
}); 

```

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [November 9, 2016, 11:05pm UTC](https://meta.discourse.org/t/censor-specific-text-patterns/26042/10 "2016-11-09T23:05:48Z")

</div>

This now exists, see

> [@Support for wildcards in word censoring](https://meta.discourse.org/t/support-for-wildcards-in-word-censoring/26866/7):
>
> Hey look what we added this week: This is a new setting that works alongside censored words, but is a regular expression. The above example filters 7 digits of a phone number. If you like it, call me at 555-1234! The value entered in the setting is checked to see if it matches too greedily like (.)\*. Also, if cooking a post ever fails because the javascript engine timed out, then the censored pattern setting will be cleared on the assumption that it’s an evil regex like (a|aa)+.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [November 9, 2016, 11:05pm UTC](https://meta.discourse.org/t/censor-specific-text-patterns/26042/11 "2016-11-09T23:05:50Z")

</div>


