#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?mx)(no)|" & @CRLF & _
"(yes)(?!.*yes)|" & @CRLF & _
"((?!(?=(?<a>[\s\S]*))(?<b>yes.*(?=\k<a>\z)|(?<=(?=x^|(?&b))[\s\S])))yes)"
Local $sString = "no/yes" & @CRLF & _
"no/yes/yes/no" & @CRLF & _
"/yes/yes/no/yes" & @CRLF & _
"no/word/no/yes/yes/yes/no" & @CRLF & _
"yes/no" & @CRLF & _
"yes/no/yes/word/yes" & @CRLF & _
"/word/yes/no/no/no/yes/yes" & @CRLF & _
"yes/no/yes/yes" & @CRLF & _
"" & @CRLF & _
""
Local $sSubst = "${1:+-:+}"
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