Ersetze einen String in allen Beiträgen

:bookmark: This guide explains how to replace a string in all posts within a Discourse instance.

:person_raising_hand: Required user level: System Administrator

:warning: Console Access Required

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

:warning: 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:

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:

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:

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:

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:

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

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

Case-insensitive deletion

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

Regex deletion

rake 'posts:delete_word[\\[color=#[0-9a-fA-F]{3,6}\\],regex]'
70 „Gefällt mir“
Batch processing to search and replace in all posts
Global Replace across database
[Announce] Search & replace / batch process Discourse posts
How do I change the legacy CDN URLs of images in posts?
How to automatically replace a double exclamation point when a message is saved?
Administrative Bulk Operations
Updating image URL's after a domain change
Replacing content in multiple topics with Regex?
Forum Link Checker
Remove BBCode and convert to Markdown
Tool to remove email addresses from posts
Bulk replacement in translated strings?
Youtube embeds missing
Fix quotes after phpBB import
Is there a way to easily replace the word "Topic" everywhere on my site at once
Shouldn't users be able to delete their accounts whenever they want?
Localised inline date/time
Watched words - replace link/url works in test but not in post
Permalink question (rewriting/redirecting old gallery contents)
Hosted to self-hosted migration: past uploads still reference discourse infra
How to fix formatting issues? - markdown badly migrated to HTML
How to run rake posts:remap with domain?
Migrate a phpBB3 forum to Discourse
Discourse Doc Categories
What is rebaking and is it necessary when moving a server?
Discourse s3 backup folder
Pin more than one topic globally
After migrating from XenForo to Discourse
Search and Replace a text string in the post database
Trouble with `discourse remap` remapping `topic_links url`
CommonMark testing started here!
Remove images from PMs that have been inactive for >1 year
Masonry Image Gallery
Redirect Article- possible?
(Superseded) Set up backup and image uploads to DigitalOcean Spaces
Upload links broken after S3 bucket change
How to search and replace URL instances throughout topics?
Enable a CDN for your Discourse
How do I move my s3 upload bucket from one provider to another?
Imgur images broken
Move from BackBlaze B2 to Digital Ocean Spaces
What's the fastest way to replace strings with multiple regexes in 1 million posts?
Too many user emails domains not working lead to mailgun domain disabled: what to do?
Renaming uploaded files
After rebuilding, avatar photos are missing
The change of from "tags" to "tag" in its URL affects my Discourse since they are linked in many posts. How can I automatically change them?
Switch from TAGS to TAG broke links in posts and "Delete Unused Tags"