# \[Announce\] Search & replace / batch process Discourse posts

**URL:** <https://meta.discourse.org/t/announce-search-replace-batch-process-discourse-posts/34029>\
**Category:** Extras\
**Tags:** rest-api\
**Created:** [October 2, 2015, 7:14am UTC](https://meta.discourse.org/t/announce-search-replace-batch-process-discourse-posts/34029 "2015-10-02T07:14:36Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![dandv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dandv/32/169779_2.png) [@dandv](https://meta.discourse.org/u/dandv)\
**Post date:** [October 2, 2015, 7:14am UTC](https://meta.discourse.org/t/announce-search-replace-batch-process-discourse-posts/34029/1 "2015-10-02T07:14:36Z")

</div>

## ==\> [Discourse-post-process](https://github.com/dandv/discourse-post-process) \<==

I’m happy to introduce this simple but powerful Node.js script that uses the [Discourse API](https://meta.discourse.org/t/discourse-api-documentation/22706) to mass-modify Discourse posts. It essentially performs a regexp-based search & replace across all posts in a forum.

After migrating a few thousand posts from MyBB to Discourse, there was various little tweaks that needed to be made (fix BBCode → Markdown conversion, re-attach attachments, fix @username mentions when the usernames have changed etc.) I’m not a Ruby coder, and [writing a simple Ruby script to post-process posts was non-trivial](https://meta.discourse.org/t/batch-processing-to-search-and-replace-in-all-posts/33621/4). Using the Discourse API was much easier.

### Features

- Apply a set of regexp-based transformations to each post, such as replacing [BBCode](https://en.wikipedia.org/wiki/BBCode) tags with Markdown ones, e.g. `[hr]` with `---`
- Mention as the edit reason all transformations that have been applied
- Warn about patterns that may cause rendering problems, such as unconverted `[list]`s or [newlines in nested quotes](https://meta.discourse.org/t/weird-parsing-rule-for-nested-quote-preceded-by-newline/33679).
- Warn about potentially missing attachments
- Detect whether `[color=]` tags have been used (install the [bbcode-color plugin](https://github.com/discourse/discourse-bbcode-color/) to support colors)
- Fix [quotes that have been incorrectly imported from MyBB (or other forums)](https://meta.discourse.org/t/mybb-import-doesnt-process-on-quoted-posts-pid-and-date/27412)

I’ve tested the script manually on ~500+ posts in the [Quantified Self Forum / Zeo thread](http://discourse.quantifiedselfforum.com/zeo) and am quite satisfied with it.

---

_[View the full topic](https://meta.discourse.org/t/announce-search-replace-batch-process-discourse-posts/34029)._
