#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)^(?=.*?(\w+)\W*(\w+)\W+([JS]r)$).*"
Local $sString = ".xy z., Jr" & @CRLF & _
"Jr, .xy z., Jr" & @CRLF & _
"Jr. xy z., Sr" & @CRLF & _
",Jr xy, z, Jr" & @CRLF & _
".Jr .xy, z., Jr" & @CRLF & _
"Sr\ .xy z., Jr" & @CRLF & _
"Ser, xy , z., Jr" & @CRLF & _
"./Sr xy,/ z., Jr" & @CRLF & _
"<<sr, xy z, Jr" & @CRLF & _
"SR, .xy z., Jr" & @CRLF & _
"[]sa, .xy z., Jr" & @CRLF & _
"ps xy z., Jr" & @CRLF & _
"asa xy z., Jr" & @CRLF & _
"asad .xy z., Jr" & @CRLF & _
"bs/ .xy z., Jr" & @CRLF & _
"p[], .xy z., Jr" & @CRLF & _
"lold.,.xy z., Jr" & @CRLF & _
"scs., .xy z., Jr" & @CRLF & _
"losdj .xy z., Jr" & @CRLF & _
".xy z., Jr" & @CRLF & _
".xy./z., Jr" & @CRLF & _
"sa .xy z., Jr"
Local $sSubst = "$3,$1,$2,$3."
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