{% assign text = 'use the keys to find multiple sections of text between keys and cut out the text between two keys.' %}
{% assign sections = text | sections: 'keys', 'text' %}
{% for section in sections %}
{{section}}
{% endfor %}
Output
to find multiple sections of
and cut out the
.
To limit the size of the array to the first n sections found, pass a positive integer into the array size limit parameter.
Input
{% assign text = 'use the keys to find multiple sections of text between keys and cut out the text between two keys.' %}
{% assign sections = text | sections: 'keys', 'text', 1 %}
{% for section in sections %}
{{section}}
{% endfor %}
Output
to find multiple sections of
To pickup all sections without a limit, pass -1 into the array size limit parameter.
Input
{% assign text = 'use the keys to find multiple sections of text between keys and cut out the text between two keys.' %}
{% assign sections = text | sections: 'keys', 'text', -1 %}
{% for section in sections %}
{{section}}
{% endfor %}
Output
to find multiple sections of
and cut out the
.
If the nth occurrence of beginning key is not found, an empty value will be returned.
Input
{{ 'use the keys to find a section of text and cut out the text between two keys.' | sections: 'keys', 'text', -1, 3 }}
Output
If the nth occurrence of ending key is not found, the remaining input will be returned.
Input
{{ 'use the keys to find a section of text and cut out the text between two keys.' | sections: 'keys', 'text', -1, 1, 5 }}
Output
to find a section of text and cut out the text between two keys.