#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?ms)(?<!\/\/\s*?)(?:var|let|const)(?:\s+)(.*?)(?:\s+)?=\s?(?:.*?);"
Local $sString = "// start file" & @CRLF & _
"" & @CRLF & _
"var nameVar1 = '';" & @CRLF & _
"// var nameVar1 = '';" & @CRLF & _
"" & @CRLF & _
"var otherVar1= "test1";" & @CRLF & _
"" & @CRLF & _
"var nameVar2 ="test2"," & @CRLF & _
" otherVar2 = 'test3';" & @CRLF & _
" " & @CRLF & _
"var nameVar3 = true;" & @CRLF & _
"" & @CRLF & _
"var otherVar3 = false ;" & @CRLF & _
"" & @CRLF & _
"var objName = {" & @CRLF & _
" test: 'test'" & @CRLF & _
"};" & @CRLF & _
"" & @CRLF & _
"var expression = nameVar1 + nameVar2;" & @CRLF & _
"" & @CRLF & _
"// comment" & @CRLF & _
"" & @CRLF & _
"for(var test in templateConfig) {" & @CRLF & _
" if( templateConfig ){ defaultLang = langParam; }" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"// end file"
Local $sSubst = "{{$1}}"
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