Liquid Remove / Replace Specific Strings Between "[" "]"

Solved
BlackboxMyCar
New Member
2 0 0

Hi there, I'm looking to create a variable string for my structured data so that we can remove certain characters out of our product title, for example:

  • [BACKORDER ETA August 10th] BlackVue DR900S-2CH IR 4K Dash Cam
  • [LIMITED QUANTITY] BlackVue DR750S-2CH IR + DR750S-1CH + BlackVue B-124X + Bonus 1 Year Warranty
  • [BACKORDER ETA July 31st] VIOFO A129 Pro Duo 4K 2-Channel Dash Cam with GPS

I would like to create a piece of code for my schema so that it removes the [...] part out of the title, so that the titles would be:

  • BlackVue DR900S-2CH IR 4K Dash Cam
  • BlackVue DR750S-2CH IR + DR750S-1CH + BlackVue B-124X + Bonus 1 Year Warranty
  • VIOFO A129 Pro Duo 4K 2-Channel Dash Cam with GPS

Here's what I've got so far, but I know it's not working:

 

"name": "{{ product.title | strip_html | escape }}",

 

I believe I should be replacing the strip_html portion with remove: "[...]", but unsure how to create an array to capture all the characters within.

Thanks for your help!

0 Likes
Propero
Shopify Partner
793 92 136

This is an accepted solution.

please try this

{% assign my_array = "[BACKORDER ETA August 10th] BlackVue DR900S-2CH IR 4K Dash Cam" | split: "]" %}

{{ my_array.last }}

 

- Was my reply helpful? Click Like or Click Accept as Solution
To hire: email us at shopify@propero.in
checkout our app https://apps.shopify.com/picamaze
0 Likes
PaulNewton
Shopify Partner
2601 136 475

@BlackboxMyCar Propero's got the output solution.

Keep in mind when creating products and putting things like "[BACKORDER ETA August 10th]" in the title that when you rename theme you  ALSO need to edit the product.handle or that incorrect title could stay in search results forever. This isn't an issue if your adding this info after a products been made unless you need that info to also show in search results or be part of the product url(product.handle)

https://help.shopify.com/en/manual/products/add-update-products#edit-a-search-engine-listing-preview

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
0 Likes
BlackboxMyCar
New Member
2 0 0

Thanks, it works!

0 Likes
huanineupane
Tourist
6 0 0

hi,

can anyone help me with this? I have a code here

 

{% assign dates = "1,2,3,4,5,6,7" | split: ","%} {% assign today = 'now' | date: '%s' %} {% assign single_day = 86400 %} {% assign preorder_days = preorder_days | split: ","%} {% assign days = days | split: ","%} {% for i in dates%} {% assign single_day = single_day | plus: 86400 %} {% assign days = today | plus: single_day | date: '%a %e %b %Y' %} <!-- {% assign days = days | split: ","%} --> {% assign preorder_days = preorder_days | concat: days %} {%endfor%} {% assign preorder_days = preorder_days | split: "," %} {% for preorder in preorder_days %} {{preorder}} {%endfor%}

 

 this will display

["Wed 11 Nov 2020" "Thu 12 Nov 2020" "Fri 13 Nov 2020" "Sat 14 Nov 2020" "Sun 15 Nov 2020" "Mon 16 Nov 2020" "Tue 17 Nov 2020"]

how can i remove the [ ] surrounding array and " " around each value.

Many thanks

0 Likes