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

**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:** 1

<div class="post-metadata">

**Author:** ![j127](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j127/32/79093_2.png) [@j127](https://meta.discourse.org/u/j127)\
**Post date:** [16 نوفمبر 2018، 3:36ص UTC](https://meta.discourse.org/t/best-way-to-search-and-replace-these-regexes/102146/1 "2018-11-16T03:36:38Z")

</div>

After searching around the forum here, I think I might be looking for `rake posts:remap`, but it wasn’t clear whether it works with regex. This is what I’m trying to do:

During an import, a couple of things in the raw post content needs updating:

The `[quote]` tags aren’t always in the format that Discourse expects, so I want to change things like this:

```plaintext
[quote=username]lorem

ipsum[/quote]

```

to this:

```plaintext
[quote=username]
lorem

ipsum
[/quote]

```

by inserting `\n` characters, probably something like `\[quote(.*?)\]` to `\[quote$1\]\n` and `\[/quote\]` to `\n\[/quote\]` whenever needed. (I still need to look up Ruby regex syntax.)

The images also broke because we moved to a subdomain, so tags like this:

```plaintext
<img src="/files/some/path/image.jpg" alt="some alt text">

```

have to be updated to

```plaintext
<img src="https://example.com/files/some/path/image.jpg" alt="some alt text">

```

Is `rake posts:remap` what I’m looking for, and is this general syntax correct?  
`rake posts:remap["\[quote(.*?)\]","\[quote$1\]\n"]`  
(I know my regex is wrong, but I’m going to figure that out later tonight.)

Would I run something like that once for each change, or is there a way to do both in one pass?

---

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