#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)^(\w+) =.*\n(?=((?!\b\1\b)[^!])*(^\1 =|\Z))"
Local $sString = "a = 10" & @CRLF & _
"a * 3" & @CRLF & _
"" & @CRLF & _
"foo = 8" & @CRLF & _
"2 - 1" & @CRLF & _
"b = 18" & @CRLF & _
"" & @CRLF & _
"c = 10" & @CRLF & _
"d = 8" & @CRLF & _
"d = 4" & @CRLF & _
"cd = 72 " & @CRLF & _
"d / 6" & @CRLF & _
"d + 1" & @CRLF & _
"" & @CRLF & _
"e = 1" & @CRLF & _
"e = 2" & @CRLF & _
"e + 1" & @CRLF & _
"" & @CRLF & _
"FooBar1 = 0" & @CRLF & _
"Fuz__ = 8" & @CRLF & _
"Fuz__ / 1" & @CRLF & _
"" & @CRLF & _
"f = 1" & @CRLF & _
"f + 1" & @CRLF & _
"f = 2" & @CRLF & _
"f + 1" & @CRLF & _
"" & @CRLF & _
"g = 1" & @CRLF & _
"1 / 5 * 8 + 4"
Local $sSubst = ""
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