#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(,\s*\"attr\" *: *\".*\"|(?=\s*\}))|(\s*\"attr\" *: *\".*\"(,|(?=\s*\})))"
Local $sString = "{"attr": "singlematch"}" & @CRLF & _
"{" & @CRLF & _
" "attr": "MYVALUE"," & @CRLF & _
" "anotherAttr0": "foobar"," & @CRLF & _
" "attr": "MYVALUE2"," & @CRLF & _
" "attr":"witthourspace"," & @CRLF & _
" "attr": 23," & @CRLF & _
" "anotherAttr1": false," & @CRLF & _
" "attr": "notin arow"," & @CRLF & _
" "anotherAttr2": "300"," & @CRLF & _
" "attr": "MYVALUE3"" & @CRLF & _
"}" & @CRLF & _
"{"attr":"single match no space"}" & @CRLF & _
"{ "attr" : "Weird spacing"}" & @CRLF & _
"{" & @CRLF & _
" "attr": "Simple json isn't collapsed but, that's fine"" & @CRLF & _
"}" & @CRLF & _
"{" & @CRLF & _
" "attr2": "bob"," & @CRLF & _
"}" & @CRLF & _
"{}" & @CRLF & _
"{" & @CRLF & _
""a":1," & @CRLF & _
""b":2," & @CRLF & _
"}" & @CRLF & _
"{" & @CRLF & _
" "attr": "fred"," & @CRLF & _
" "attr": "Joe"," & @CRLF & _
" "attr": "Hey!"" & @CRLF & _
"}" & @CRLF & _
"{" & @CRLF & _
""a":2," & @CRLF & _
" "attr":"test"," & @CRLF & _
" "bob":2," & @CRLF & _
"}"
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