# Replacing content in multiple topics with Regex?

**URL:** https://meta.discourse.org/t/replacing-content-in-multiple-topics-with-regex/294828
**Category:** Migration
**Created:** [February 9, 2024, 1:32pm UTC](https://meta.discourse.org/t/replacing-content-in-multiple-topics-with-regex/294828 "2024-02-09T13:32:43Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Ventrilo](https://avatars.discourse-cdn.com/v4/letter/v/b487fb/32.png) [@Ventrilo](https://meta.discourse.org/u/Ventrilo)
#### Post date: [February 9, 2024, 1:32pm UTC](https://meta.discourse.org/t/replacing-content-in-multiple-topics-with-regex/294828/1 "2024-02-09T13:32:44Z")

</div>

Hey,

in a lot of my imported content i have a link from the old domain in topics i imported like this:

[https://domain.com/threads/xxxx](https://domain.com/threads/xxxx)

where xxxx is represented by a 4 digit thread number,

I just want to complete remove this string from all topics, what would be the best way to achieve this en-bulk to 3,000+ topics?

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [February 9, 2024, 1:37pm UTC](https://meta.discourse.org/t/replacing-content-in-multiple-topics-with-regex/294828/2 "2024-02-09T13:37:30Z")

</div>

Hi,

This should help:

> [@Replace a string in all posts](https://meta.discourse.org/t/replace-a-string-in-all-posts/48729):
>
> 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…

---

<div class="post-metadata">

### Author: ![Ventrilo](https://avatars.discourse-cdn.com/v4/letter/v/b487fb/32.png) [@Ventrilo](https://meta.discourse.org/u/Ventrilo)
#### Post date: [February 9, 2024, 1:50pm UTC](https://meta.discourse.org/t/replacing-content-in-multiple-topics-with-regex/294828/3 "2024-02-09T13:50:21Z")

</div>

Hey thanks!

```plaintext
rake posts:delete_word['^http:\/\/domain.com\/threads\/.*.\/$','regex']

```

pulls up 0 results, know where I’m going wrong?

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [February 9, 2024, 2:11pm UTC](https://meta.discourse.org/t/replacing-content-in-multiple-topics-with-regex/294828/4 "2024-02-09T14:11:53Z")

</div>

Try:

```plaintext
rake posts:delete_word['https?://domain\.com/threads/\\d{4}','regex']

```

---

<div class="post-metadata">

### Author: ![Ventrilo](https://avatars.discourse-cdn.com/v4/letter/v/b487fb/32.png) [@Ventrilo](https://meta.discourse.org/u/Ventrilo)
#### Post date: [February 9, 2024, 2:53pm UTC](https://meta.discourse.org/t/replacing-content-in-multiple-topics-with-regex/294828/5 "2024-02-09T14:53:06Z")

</div>

Amazing! worked perfectly, been reading the post you linked and im trying to build a regex for removing RGB BB code.

RegEx builder states my regex is valid:

 ![image](https://global.discourse-cdn.com/meta/original/4X/6/3/4/63444c27589c594db77e8cf773394285dc65bbda.png)

However when running it, it either updates 0 posts or I get an error stating it isn’t a valid regex.

This his how the BBcode is in topics:

[COLOR=rgb(95, 66, 222)]

Also tried this:

rake posts:delete\_word[‘[\WCOLOR=rgb(\d{1,3}), (\d{1,3}), (\d{1,3})(, ){0,1}(0(\.\d+)?|1(\.0+)?)]’,‘regex’]

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 9, 2024, 3:37pm UTC](https://meta.discourse.org/t/replacing-content-in-multiple-topics-with-regex/294828/6 "2024-02-09T15:37:37Z")

</div>

Wouldn’t you rather have those links work? And maybe just change the hostname?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 9, 2024, 3:19pm UTC](https://meta.discourse.org/t/replacing-content-in-multiple-topics-with-regex/294828/7 "2024-02-09T15:19:31Z")

</div>

You can use my example [in the other topic where this was discussed](https://meta.discourse.org/t/replace-a-string-in-all-posts/48729/166) for how to do it in rails and use [http://rubular.com/](http://rubular.com/) to tweak your regex.
