- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2022 11:17 PM
Hello,
I created a simple Regex, to dynamically change the background color in an email template. The Color appears in 2 places in the template (this cannot be changed!). When I run the Regex - Replace function, it changes just the first occurrence.
Any idea what I'm doing wrong? What could be done for it to work as expected and change both instances?
Regex:
The String:
.....
<tr style="height: 17.55pt;">
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 04:39 AM
Hi,
yes you're right. In the end, it was fixed by using /gm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 12:34 AM
Hi,if you want to replace all values use the global flag IE /yourregex/g
https://www.w3schools.com/jsref/jsref_replace.asp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 04:39 AM
Hi,
yes you're right. In the end, it was fixed by using /gm

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 03:59 AM
Hi Pavel,
Instead of .replace(), use .replaceAll().
body = body.replaceAll(r2, "background: " + RAG + ';');
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll