Get substring from string in Liquid?
split
to the rescue !
{% assign str = 'garbage <h1>TITLE</h1> moregarbage' %}
{% assign a = str | split: '<h1>' %}
We now have garbage
in a[0] and TITLE</h1> moregarbage
in a[1]
{% assign b = a[1] | split: '</h1>' %}
We now have TITLE
in b[0] and moregarbage
in b[1]
I know this is ancient, but for anyone else coming across it: https://shopify.github.io/liquid/basics/operators/
contains contains checks for the presence of a substring inside a string.
{% if product.title contains "Pack" %} This product's title contains the word Pack. {% endif %}
contains can also check for the presence of a string in an array of strings.
{% if product.tags contains "Hello" %} This product has been tagged with "Hello". {% endif %}
contains can only search strings. You cannot use it to check for an object in an array of objects.