#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "_meta:\d+:"
Local $sString = "{" & @CRLF & _
" "webservers": {" & @CRLF & _
" "hosts": ["123.456.789", "123.987.963"]," & @CRLF & _
" "vars": {" & @CRLF & _
" "user": "Var Value"" & @CRLF & _
" }" & @CRLF & _
" }," & @CRLF & _
" "_meta:1:": {" & @CRLF & _
" "10.201.200.68": {" & @CRLF & _
" "host1": "value1"," & @CRLF & _
" "host3": "value3"" & @CRLF & _
" }" & @CRLF & _
" }," & @CRLF & _
" "apache": {" & @CRLF & _
" "hosts": ["123.456.789", "123.987.963"]," & @CRLF & _
" "vars": {" & @CRLF & _
" "gathering_facts": "no"" & @CRLF & _
" }" & @CRLF & _
" }," & @CRLF & _
" "_meta:2:": {" & @CRLF & _
" "10.201.200.54": {" & @CRLF & _
" "host1": "value1"," & @CRLF & _
" "ho3": "value3"" & @CRLF & _
" }" & @CRLF & _
" }," & @CRLF & _
" "ecs": {" & @CRLF & _
" "hosts": ["123.456.789", "123.987.963"]," & @CRLF & _
" "vars": {" & @CRLF & _
" "gathering_facts": "no"" & @CRLF & _
" }" & @CRLF & _
" }," & @CRLF & _
" "_meta:3:": {" & @CRLF & _
" "10.201.200.54": {" & @CRLF & _
" "host1": "value1"," & @CRLF & _
" "host3": "value3"" & @CRLF & _
" }" & @CRLF & _
" }," & @CRLF & _
"}"
Local $sSubst = "_meta"
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