# Regexreplace multiple strings in a loop with FORMATTING?

**URL:** <https://connect.superhuman.com/t/regexreplace-multiple-strings-in-a-loop-with-formatting/48226>\
**Category:** Ask the Community\
**Created:** [April 24, 2024, 11:15am UTC](https://connect.superhuman.com/t/regexreplace-multiple-strings-in-a-loop-with-formatting/48226 "2024-04-24T11:15:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon\_Dallas](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/jon_dallas/32/30836_2.png) [@Jon\_Dallas](https://connect.superhuman.com/u/Jon_Dallas)\
**Post date:** [April 24, 2024, 11:15am UTC](https://connect.superhuman.com/t/regexreplace-multiple-strings-in-a-loop-with-formatting/48226/1 "2024-04-24T11:15:02Z")

</div>

Hello!

Is it possible to use substituteAll() or regexreplace() recursively in a loop on the same original “haystack” text to bold certain parts using \_bold()?

The goal is to use replace/substitute to bold (or any kind of format function) multiple words in a paragraph.

So, for example, given Columns A and B, this formula would produce Column C:

- Column A: Rudolph the red nosed reindeer.
- Column B: red, reindeer
- Column C: Rudolph the **red** nosed **reindeer**.

Earlier in [this thread](https://connect.superhuman.com/t/regexreplace-multiple-strings-with-a-loop/47717/7), @Rickard_Abraham discovered that Coda does have support for regex capturing groups and we can use this formula to recursively wrap the chosen text in brackets:

`thisRow.[Original Paragraph].RegexReplace("(" + thisRow.[Words to Wrap in Brackets].Join("|") + ")", "[$1]")`

But this same formula doesn’t work with formatting functions like \_highlight() or \_bold().

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Paul\_Danyliuk](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/paul_danyliuk/32/27228_2.png) [@Paul\_Danyliuk](https://connect.superhuman.com/u/Paul_Danyliuk)\
**Post date:** [April 24, 2024, 12:07pm UTC](https://connect.superhuman.com/t/regexreplace-multiple-strings-in-a-loop-with-formatting/48226/2 "2024-04-24T12:07:28Z")

</div>

Oh, I remember pulling this off quite a while ago. Of course I wouldn’t find it now 😅

I recently solved a somewhat similar thing. It was about replacing `{{Named}} {{parameters}}` with ready-to-`Format()` placeholders like `{1} {2}` etc. and applying proper values to those. And my solution preserved formatting. I have only recorded a very improvised video on that, which I shared with patrons, but I was too overwhelmed to make a proper tutorial out of it yet.

The short answer is, it’s only possible with some effort. I don’t remember if Substitute preserves formatting (probably not / not yet?) but RegexAnything functions for sure don’t.

* * *

P.S. Oh, I guess that’s it. Here I was replacing sought words with underlined versions of them.  
RegexExtract isn’t a hidden formula anymore, and we didn’t have WithName back then, so today you can easily make it into a single formula.

> [@Highlight words in column based on master list of words](https://connect.superhuman.com/t/highlight-words-in-column-based-on-master-list-of-words/17458/5):
>
> Here’s a solution that can match phrases. It’s a multi-step one though. Also it should be a more robust one than the one above, since it doesn’t split the text by every word but only wherever necessary to then stitch it back. It uses a hidden RegexExtract formula; it supports flags so instead of using Lower() elsewhere I just set it up to work as case-insensitive.

---

<div class="post-metadata">

**Author:** ![Ryan\_Martens2](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/ryan_martens2/32/19566_2.png) [@Ryan\_Martens2](https://connect.superhuman.com/u/Ryan_Martens2)\
**Post date:** [April 27, 2024, 10:42am UTC](https://connect.superhuman.com/t/regexreplace-multiple-strings-in-a-loop-with-formatting/48226/3 "2024-04-27T10:42:23Z")

</div>

When I read the title of your post, I thought you wanted to do replace-like operations on **formatted** text. So, I admit I spent way too much time thinking about this problem. Paul’s and BenLee’s approaches are both good, but there are some limitations. Check out this demo if you’re interested.

[Open in new tab.](https://coda.io/embed/fGub6hdjEl/_susOI?viewMode=embedplay)

https://coda.io/embed/fGub6hdjEl/_susOI?viewMode=embedplay

---

<div class="post-metadata">

**Author:** ![Max\_OBrien](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/max_obrien/32/49285_2.png) [@Max\_OBrien](https://connect.superhuman.com/u/Max_OBrien)\
**Post date:** [April 27, 2024, 4:04pm UTC](https://connect.superhuman.com/t/regexreplace-multiple-strings-in-a-loop-with-formatting/48226/4 "2024-04-27T16:04:09Z")

</div>

the demo looks great, but its read-only, so we cannot see the formulas being used.

---

<div class="post-metadata">

**Author:** ![Ryan\_Martens2](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/ryan_martens2/32/19566_2.png) [@Ryan\_Martens2](https://connect.superhuman.com/u/Ryan_Martens2)\
**Post date:** [April 28, 2024, 6:37am UTC](https://connect.superhuman.com/t/regexreplace-multiple-strings-in-a-loop-with-formatting/48226/5 "2024-04-28T06:37:29Z")

</div>

It’s set to comment-only, but you can still explore the formulas in the little embed window or [open in a new tab](https://coda.io/embed/fGub6hdjEl/_susOI?viewMode=embedplay). (also added this link to my first post)

---

<div class="post-metadata">

**Author:** ![system](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/system/32/24484_2.png) [@system](https://connect.superhuman.com/u/system)\
**Post date:** [July 27, 2024, 6:37am UTC](https://connect.superhuman.com/t/regexreplace-multiple-strings-in-a-loop-with-formatting/48226/6 "2024-07-27T06:37:29Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
