You can use this pattern:
$pattern = '~\$db_host\s*=\s*(["\'])\s*\1\s*;~';
\s*
means "any white character zero or more times". White characters are spaces, tabs, carriage returns and newlines, but if you want, you can replace \s
by \h
that matches only horizontal white characters (i.e. tabs and spaces).
I put the type of quote in a capturing group with (["\'])
and then I use a backreference to this group with \1
(1 because it is the first capturing group of the pattern).