how to select regex matches in jinja2?
<h2>toy example</h2>

<p>Essentially, I want to do something like:</p>

<pre><code>['hello', 'apple', 'rare', 'trim', 'three'] | select(match('.*a[rp].*'))
</code></pre>

<p>Which would yield:</p>

<pre><code>['apple', 'rare']
</code></pre>

<h2>what am I talking about?</h2>

<p>The <a href="http://docs.ansible.com/ansible/playbooks_filters.html#other-useful-filters" rel="noreferrer"><code>match</code></a> filter and <a href="http://jinja.pocoo.org/docs/dev/templates/#select" rel="noreferrer"><code>select</code></a> filter. My issue arises from the fact that the select filter only supports unary "tests".</p>

<p>I'm on Ansible 1.9.x.</p>

<h2>my actual use case</h2>

<p>...is closer to:</p>

<pre><code>lookup('dig', ip_address, qtype="PTR", wantList=True) | select(match("mx\\..*\\.example\\.com"))
</code></pre>

<p>So, I want to get all the PTR records associated with an IP and then filter out all the ones that don't fit a given regex. I'd also want to ensure that there's only one element in the resulting list, and output that element, but that's a different concern.</p>