match - Liquid Filter Reference
On this page
Description
Returns the items in a list, or the characters in a string, that match the supplied regular expression.
| Property | Value |
|---|---|
| Return Type | list |
| Category | text, lists |
Write the pattern without surrounding slashes: match: "a.*e", not match: "/a.*e/". Slashes in the pattern are matched as literal characters.
- List input returns the items that match. Items that are not text, such as
nilor a map, are skipped. - String input returns the matched characters, followed by each capture group.
- A pattern that runs longer than 0.1 seconds returns an empty list, and a warning naming the pattern appears in the web console. Rewrite the pattern to avoid nested repetition such as
(a|a)*. - An invalid pattern returns nothing.
Examples
These examples use this list:
```liquid
{% assign fruits = “apple,banana,cherry,date” | split: “,” %} ```
```liquid
{{ fruits | match: “a” | join: “, “ }} ```
Output: apple, banana, date
```liquid
{{ fruits | match: “a.*e” | join: “, “ }} ```
Output: apple, date
```liquid
{{ “metamorphosis” | match: “a.*s” | join: “, “ }} ```
Output: amorphosis
```liquid
{{ “metamorphosis” | match: “(a)(m)(o)” | join: “, “ }} ```
Output: amo, a, m, o
Was this article helpful?
Thanks for your feedback! It helps us improve our docs.