# Global replace for bbcode \[code\] with backticks

**URL:** https://meta.discourse.org/t/global-replace-for-bbcode-code-with-backticks/111097
**Category:** Support
**Created:** [March 8, 2019, 4:44pm UTC](https://meta.discourse.org/t/global-replace-for-bbcode-code-with-backticks/111097 "2019-03-08T16:44:44Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![eboehnisch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eboehnisch/32/133429_2.png) [@eboehnisch](https://meta.discourse.org/u/eboehnisch)
#### Post date: [March 8, 2019, 4:44pm UTC](https://meta.discourse.org/t/global-replace-for-bbcode-code-with-backticks/111097/1 "2019-03-08T16:44:44Z")

</div>

Dear all,

I’ve just tried to run the many examples for a global find-and-replace here in this forum but struggled with two things:

1. How do I run these `rake posts: ...` commands? When I type the command at the command line I just end up with a new line showing a `>`. I’ve never done anything with Ruby so far.
2. How can I replace the string “[code]” with “```” followed by a newline?
3. Can I _search_ also for a newline so that only replace “[code]” that follows a newline?

Sorry for all these noob questions but I’m new to Discourse and in the midde of a large website relaunch 😕

Eric

---

<div class="post-metadata">

### Author: ![eboehnisch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eboehnisch/32/133429_2.png) [@eboehnisch](https://meta.discourse.org/u/eboehnisch)
#### Post date: [March 10, 2019, 2:16pm UTC](https://meta.discourse.org/t/global-replace-for-bbcode-code-with-backticks/111097/2 "2019-03-10T14:16:03Z")

</div>

I solved the problem (sleeping over it revealed the problem). I typed:

````plaintext
rake posts:remap["[code]","```"]

````

The three backticks where interpreted by the shell and so caused it to ask me to complete the command. Therefore the additional prompt that I confused for a rake prompt.

Replacing now.

Eric

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 12, 2019, 1:27am UTC](https://meta.discourse.org/t/global-replace-for-bbcode-code-with-backticks/111097/3 "2019-03-12T01:27:18Z")

</div>

I think you are also going to need to replace `[/code]` also maybe you need a newline.

---

<div class="post-metadata">

### Author: ![eboehnisch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eboehnisch/32/133429_2.png) [@eboehnisch](https://meta.discourse.org/u/eboehnisch)
#### Post date: [March 12, 2019, 7:50am UTC](https://meta.discourse.org/t/global-replace-for-bbcode-code-with-backticks/111097/4 "2019-03-12T07:50:50Z")

</div>

Done exactly that. I replaced `[code]` with `\n` and three backticks, and `[/code]` with three backticks and `\n`. Looks fine now. In the end I used Postgres instead of `remap` because I couldn’t get it to insert the newlines correctly.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 12, 2019, 7:52am UTC](https://meta.discourse.org/t/global-replace-for-bbcode-code-with-backticks/111097/5 "2019-03-12T07:52:42Z")

</div>

> [@eboehnisch](#):
>
> I couldn’t get it to insert the newslines correctly.

We do want to get that sorted in our remap somehow, for sure.

---

<div class="post-metadata">

### Author: ![AndyBr](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@AndyBr](https://meta.discourse.org/u/AndyBr)
#### Post date: [December 27, 2020, 11:38pm UTC](https://meta.discourse.org/t/global-replace-for-bbcode-code-with-backticks/111097/6 "2020-12-27T23:38:37Z")

</div>

I am unable to insert newlines either using `rake posts:remap` with the regex replace. No idea if it can even be done.

Q: If I do updates with via the database, do I need to edit both the raw and cooked versions, or if I update the raw will it update the cooked version automagically or do I need to do something to have it update?

I assume the [data explorer](https://meta.discourse.org/t/32566?silent=true) plugin just does Queries and doesn’t do UPDATEs?
