$re = '/set \$(\w+)\s+([^\s]+)/m';
$str = '#========= Variables =========
set $win Mod4
set $alt Mod1
set $ws1 "1"
set $ws2 "2"
set $ws3 "3"
set $ws4 "4"
set $ws5 "5"
set $ws6 "6"
set $ws7 "7"
set $ws8 "8"
set $ws9 "9"
set $ws0 "0"
set $bar $HOME/.config/polybar/launch.sh
set $locker i3lock -i $HOME/.config/i3/bg.png
set $term kitty
set $menu dmenu -i -l 10
set $browser qutebrowser
set $filemanager kitty -e ranger
set $launcher dmenu_run
set $notify_daemon dunst
set $notify_bar_program xob
set $notify_bar /tmp/xobpipe
set $script $HOME/.config/i3/scripts
set $last_action /tmp/i3/last_action
set $counter /tmp/i3/counter
set $windows /tmp/i3/windows
set $current_workspace i3-msg -t get_workspaces | jq -r \'.[] | select(.focused==true).name\'
#============================
#======== Autostart =========
exec nm-applet
exec kotatogram-desktop
exec $browser
exec --no-startup-id dunst
#============================';
$subst = "\1=\"\2\"";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php