I want to match a pattern, replace part of the pattern, and use a variable within the pattern as part of the replacement string.
Is this correct?
/s/^((\s+)private\sfunction\s__construct\(\))/(2)def\s__init__
In English: Replace any amount of whitespace followed by the string "private function __construct()" with the same amount of whitespace and the string def __init__. So, is my regex bad or what?

This is called a backreference, and you use
\ito refer to the i’th captured group from the pattern.So for the pattern
^((\s+)private\sfunction\s__construct\(\)), the replacement is\2def __init__.