php/regex: How to replace part of a found pattern, but leaving the rest
https://stackoverflow.com/questions/2126833/php-regex-how-to-replace-part-of-a-found-pattern-but-leaving-the-rest-as-it-is
WEBJan 24, 2010 · If your regex matches only the relevant part, it should be no problem that it replaces the complete match (like preg_replace('/X/', 'Z', $string)). But if you need the regex to contain parts that should not be replaced, you need to capture them and insert them back: preg_replace('/(non-replace)X(restofregex)/', '$1Z$2', $string);
DA: 82 PA: 45 MOZ Rank: 19