#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?i)((?:[\w'-]+,\s+)+(?:[\w'-]+\s){0,2}[\w'-]+)(\s+(and|or)\s+[\w'-]+)"
Local $sString = "I love my parents, Bon Jovi and Lada Gaga." & @CRLF & _
"" & @CRLF & _
"We invited the strippers, Hitler and Stalin." & @CRLF & _
"" & @CRLF & _
"The problem is, you can never know if the user is making a list, or just typing a bunch of words and inserting commas." & @CRLF & _
"" & @CRLF & _
"I'm not sure whether to eat, shoot or leave!" & @CRLF & _
"" & @CRLF & _
"List of words: can, can't and won't." & @CRLF & _
"" & @CRLF & _
"I will not use three-legged, blue or wooden stools." & @CRLF & _
"" & @CRLF & _
"Don't get this one or I'll be upset at you." & @CRLF & _
"" & @CRLF & _
"Put a command before this and I'll be sad."
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