Best/any way to use a regular expression in a notification

Highlighted
Shopify Partner
30 0 4

I'm looking to remove any phrase that matches a Regex inside our order confirmation notifications, specifically for item titles. Is there any way to do this with liquid, thinking it might be doable with the JavaScript liquid tag but I haven't used that much at all and I don't have the slightest clue how it will behave in notifications. The alternative is to add a metafield for each product that has the title with the phrase already replaced and to use that in the email but I'd like to avoid doing that if possible. Thanks.

0 Likes

Hey Adam,

 

The email notification templates don't support regex or javascript, so you'd need to do it in pure liquid. Depending on how complicated the matching is, it may or may not be feasible. Something like this:

 

{% for line_item in line_items %}
  {{ line_item.title | replace: "xyz", "" | replace: "abc", "" }}
{% endfor %}

 

Hope it helps.

 

Bjorn

Bjorn Forsberg | FORSBERG+two | Award-winning Shopify Apps since 2011
0 Likes