# Replace a string in all posts

**URL:** https://meta.discourse.org/t/replace-a-string-in-all-posts/48729
**Category:** Self-Hosting
**Tags:** how-to
**Created:** [August 17, 2016, 10:23am UTC](https://meta.discourse.org/t/replace-a-string-in-all-posts/48729 "2016-08-17T10:23:49Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [August 17, 2016, 10:23am UTC](https://meta.discourse.org/t/replace-a-string-in-all-posts/48729/1 "2016-08-17T10:23:49Z")

</div>

> 🔖 This guide explains how to replace a string in all posts within a Discourse instance.
> 
> 🙋 Required user level: System Administrator
> 
> ⚠ Console Access Required

Want to replace a string in all the posts on a site? Let’s get started!

> ⚠ **WARNING:** We _strongly_ recommend you take a full backup before proceeding, and make _sure_ your string replacement is specific enough to affect _only_ the places you want it to. If this string replacement goes wrong, every post on your site will look broken!

## Access your site

Start by accessing your Discourse instance via SSH and entering the Docker container:

```bash
cd /var/discourse
./launcher enter app

```

## Performing string replacements

### Basic case-sensitive replacement

To replace a string, use the following command. Replace `find` with the string to locate and `replace` with the desired substitution:

```bash
rake 'posts:remap[find,replace]'

```

Example results:

> find —\> replace  
> Find —\> Find  
> FIND —\> FIND  
> finders keepers —\> replaceers keepers  
> finding —\> replaceing

This method can be useful for tasks such as replacing emojis:

```bash
rake 'posts:remap[:slightly_smiling:,:slight_smile:]'

```

The above command will replace all occurrences of `:slightly_smiling:` with `:slight_smile:`.

### Case-insensitive replacement

For replacements that ignore case sensitivity use:

```bash
rake 'posts:remap[find,replace,string,true]'

```

Example results:

> find —\> replace  
> Find —\> replace  
> FIND —\> replace  
> finders keepers —\> replaceers keepers  
> finding —\> replaceing

### Regex replacement

For advanced replacements with regex, format the command accordingly:

```bash
rake 'posts:remap[(?<!\\w)(?=\\w)find(?<=\\w)(?!\\w),replace,regex]'

```

Example results:

> replace —\> replace  
> Find —\> Find  
> FIND —\> FIND  
> finders keepers —\> finders keepers  
> finding —\> finding

## Deleting words or strings

To completely remove a word or string, apply these commands:

### Basic case-sensitive deletion

```bash
rake 'posts:delete_word[word-to-delete]'

```

### Case-insensitive deletion

```bash
rake 'posts:delete_word[word-to-delete,string,true]'

```

### Regex deletion

```bash
rake 'posts:delete_word[\\[color=#[0-9a-fA-F]{3,6}\\],regex]'

```

> Last edited by @SaraDev 2024-11-14T00:39:05Z
> 
> > **Check document**
> >
> > Perform check on document:

---

_[View the full topic](https://meta.discourse.org/t/replace-a-string-in-all-posts/48729)._
