Twig replace filter - use part of regex match Using replace filter we can match pattern using regular expressions, but can we use part of the matched string in the second argument of filter? For example, I want to match all numbers and replace each matched number with a matched number enclosed in parentheses.
Craft's replace filter will just use PHP's preg_replace method behind the scenes if it detects that a regular expression has been passed in.

It sounds like you're looking for the PHP preg_match method, which isn't available natively.

There was a plugin that added support for this in Craft 2, but I don't think it's been ported to Craft 3. You might be able to use that as a starting point if you'd like to port it, though.