#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?x)(?: # Non capturing group 1" & @CRLF & _
" \G # Matches where the regex engine stops in the previous step" & @CRLF & _
" (\w+) # capture group 1: a regex word of 1+ chars" & @CRLF & _
" \h* # zero or more horizontal spaces (space, tabs)" & @CRLF & _
" (?: # Non capturing group 2" & @CRLF & _
" =\h* # literal '=' follower by zero or more hspaces" & @CRLF & _
" (\w+) # capture group 2: a regex word of 1+ chars" & @CRLF & _
" )? # make the non capturing group 2 optional" & @CRLF & _
")+ # repeat the non capturing group 1, one or more"
Local $sString = "Key name = value"
Local $sSubst = "\1\2"
Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst)
MsgBox($MB_SYSTEMMODAL, "Result", $sResult)
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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm