#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?:spirit_animals\s*=\s*\{|(?!^)\G)\s*'\K([^']+)('\s*:\s*'[^']+',?)"
Local $sString = "var cool_spirit_animals = {" & @CRLF & _
" 'Abel': 'unicorn'," & @CRLF & _
" 'Bob': 'lion'" & @CRLF & _
" };" & @CRLF & _
"" & @CRLF & _
" var spirit_plants = {" & @CRLF & _
" 'Cain': 'venus fly trap'" & @CRLF & _
" };" & @CRLF & _
"" & @CRLF & _
" var stupid_spirit_animals = {" & @CRLF & _
" 'Dan': 'lamprey'" & @CRLF & _
" };" & @CRLF & _
"" & @CRLF & _
" var spirit_vampires = {" & @CRLF & _
" 'Emily': 'Buffy'," & @CRLF & _
" 'Fred': 'Dracula'" & @CRLF & _
" };"
Local $sSubst = "$1 Smith$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