#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "([a-zA-Z]+)\s([a-zA-Z]+)"
Local $sString = "" & @CRLF & _
"1 Agra Achhnera NIL" & @CRLF & _
"2 Agra Agra NIL" & @CRLF & _
"3 Agra Fatehabad NIL" & @CRLF & _
"4 Agra Fatehpur Sikri NIL" & @CRLF & _
"5 Agra Jagner NIL" & @CRLF & _
"6 Agra Jarar NIL" & @CRLF & _
"7 Agra Khairagarh NIL" & @CRLF & _
"8 Agra Shamshabad NIL" & @CRLF & _
"9 Aligarh Atrauli NIL" & @CRLF & _
"10 Aligarh Chharra NIL" & @CRLF & _
"11 Aligarh Aligarh 1300.00" & @CRLF & _
"12 Aligarh Khair 1300.00" & @CRLF & _
"13 Allahabad Allahabad NIL"
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