# أفضل طريقة للبحث والاستبدال لهذه التعابير النمطية؟

**URL:** <https://meta.discourse.org/t/best-way-to-search-and-replace-these-regexes/102146>\
**Category:** Product Support\
**Created:** [16 نوفمبر 2018، 3:36ص UTC](https://meta.discourse.org/t/best-way-to-search-and-replace-these-regexes/102146 "2018-11-16T03:36:38Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![fhe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fhe/32/113345_2.png) [@fhe](https://meta.discourse.org/u/fhe)\
**Post date:** [16 نوفمبر 2018، 7:21ص UTC](https://meta.discourse.org/t/best-way-to-search-and-replace-these-regexes/102146/2 "2018-11-16T07:21:12Z")

</div>

> [@j127](#):
>
> Is `rake posts:remap` what I’m looking for, and is this general syntax correct?  
> `rake posts:remap["\[quote(.*?)\]","\[quote$1\]\n"]`

You can use `rake posts:remap` to do this, but I think you need to specify `"regex"` as 3rd parameter, otherwise the other parameters are treated as strings.

Another option is to use the rails console and use Ruby to do the update:

```plaintext
imported_posts = Post.where("id < your_last_imported_post_id")
imported_posts.find_each do |post|
  raw = post.raw.gsub(/<your magic regex here>/, "<your replacement here>")
  post.update_column(:raw, raw)
end

```

This way, you can also perform a dry run first, output the possible matches and accompanying replacements and see whether everything works as intended. Multiple replacements in one run are of course also possible then.

---

_[View the full topic](https://meta.discourse.org/t/best-way-to-search-and-replace-these-regexes/102146)._
