#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(x(\d)(,)?)(x(\d)(,)?)?"
Local $sString = "X1,O1,X2,O2,Z3,X4,O4,Z5,X6,O6 <- repeated groups broken apart" & @CRLF & _
"x1,x2,Z3,x4,Z5,x6" & @CRLF & _
"X1,X2,O1,O2,Z3,X4,O4,Z5,X6,O6 <- repeated groups kept together"
Local $sSubst = "X$2,X$5$3O$2,O$5$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