#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)\w+\s*\n|([\w ]+)\n*(\1\n+)*"
Local $sString = "we" & @CRLF & _
"all" & @CRLF & _
"have" & @CRLF & _
"a" & @CRLF & _
"unique" & @CRLF & _
"perspective" & @CRLF & _
"on" & @CRLF & _
"the" & @CRLF & _
"we all have a unique perspective on the" & @CRLF & _
"" & @CRLF & _
"we all have a unique perspective on the" & @CRLF & _
"world" & @CRLF & _
"around" & @CRLF & _
"us" & @CRLF & _
"and" & @CRLF & _
"believe" & @CRLF & _
"it" & @CRLF & _
"or" & @CRLF & _
"not" & @CRLF & _
"world around us and believe it or not" & @CRLF & _
"" & @CRLF & _
"world around us and believe it or not" & @CRLF & _
""
Local $sSubst = "\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