We introduce the "match" filter, which accepts a Ruby-compatible regular expression, and returns the matching string. Use {{ match.captures }}
and {{ match.named_captures }}
to retrieve captured values.
{{ "It's a lovely day!" | match: "(?<=a ).*(?= day)" }}
=> "lovely"
{% assign match = "It's a lovely day!" | match: "a (bucolic|lovely) day" %}
{{ match.captures }}
=> ["lovely"]
{% assign match = "It's a lovely day!" | match: "a (?<adjective>bucolic|lovely) day" %}
{{ match.named_captures.adjective }}
=> {"adjective"=>"lovely"}
{% assign match = "It's a lovely day!" | match: "a (?i:LOVELY) day" %}
{{ match }}
=> "a lovely day"