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
This is called a backreference, and you use \i to refer to the i'th captured group from the pattern.
\i
So for the pattern ^((\s+)private\sfunction\s__construct\(\)), the replacement is \2def __init__.
^((\s+)private\sfunction\s__construct\(\))
\2def __init__