PHP. Named groups in the replacement string

php, regex

Solution

You can't - only numeric match names are usable with `preg_replace()`.

Problem

How to use named groups in the replacement string? This expression creates a named group : ``` $re= "/(?P<name>[0-9]+)/"; ``` I would like to replace this expression, but it does not work. ``` preg_replace($re, "\{name}", $text); ```

Original source