#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "\b((?:id)*)(?=\S)|((?:id)+\b|\b(?<!id))|((?:id)+)"
Local $sString = "longstringwithid1234andid4321init" & @CRLF & _
"" & @CRLF & _
"id1id2id3" & @CRLF & _
"" & @CRLF & _
"id213123213id12321321id" & @CRLF & _
"id123421321id12312321id65464" & @CRLF & _
"thereisandidanditsnameisbingoidbingoidbingoid2312321" & @CRLF & _
"ghjjhghjgd" & @CRLF & _
"dsadsadasdsaididididididdsadsadsa" & @CRLF & _
"dsa" & @CRLF & _
"das id dsadassa id sdadasdsa " & @CRLF & _
"idsa2311321id2312312id21321312" & @CRLF & _
"" & @CRLF & _
"ididid1idid2idid3ididid"
Local $sSubst = "${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