#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?x)(?(DEFINE)" & @CRLF & _
" (?<nestedBrackets> \[ [^][]* (?:\g<nestedBrackets>[^][]*)*+ ] )" & @CRLF & _
")" & @CRLF & _
"" & @CRLF & _
"(?: # two possible entry points" & @CRLF & _
" \G(?!\A) # 1. contiguous to a previous match" & @CRLF & _
" | # OR" & @CRLF & _
" [^[]* \[ # 2. all characters until an opening bracket" & @CRLF & _
")" & @CRLF & _
"" & @CRLF & _
"# all possible characters until "," or the closing bracket:" & @CRLF & _
"[^]["]* # all that is not ] [ or "" & @CRLF & _
"(?:" & @CRLF & _
" \g<nestedBrackets> [^]["]* # possible nested brackets" & @CRLF & _
" | # OR" & @CRLF & _
" "(?!,") [^]["]* # a quote not followed by ,"" & @CRLF & _
")*+ # repeat as needed" & @CRLF & _
"\K # remove all on the left from match result" & @CRLF & _
"(?:" & @CRLF & _
" "," # match the target" & @CRLF & _
" |" & @CRLF & _
" ] (*SKIP)(*F) # closing bracket: break the contiguity" & @CRLF & _
")"
Local $sString = "[word:"pla pla","pla pla","[other_word:"pla pla","[word:"pla","pla"end word]","pla pla"end other_word]","pla pla","[word:"pla","pla"end word]"end word]",""
Local $sSubst = "|,|"
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