#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "\[\[(?:[^][]*|\[(?!\[)|\](?!\]))*+\]\]\K|\[\[ ?| ?\]\]"
Local $sString = "Locate instances of nested double square brackets and remove the outer double square brackets" & @CRLF & _
"" & @CRLF & _
"I'm using TextMate (but happy to use any suitable search and replace program) to query a set of files (these files are my notes in Logseq if its relevant)." & @CRLF & _
"" & @CRLF & _
"I'm looking to find and replace instances of nested double square brackets and remove the outer double square brackets" & @CRLF & _
"" & @CRLF & _
"eg 1 - Normal nesting" & @CRLF & _
"" & @CRLF & _
" [[ any text or no text [[ any text ]] any text or no text]]" & @CRLF & _
" " & @CRLF & _
"" & @CRLF & _
"eg 2 - Compound nesting " & @CRLF & _
"" & @CRLF & _
" [[ any text or no text [[ any text ]] [[ any text ]] any text or not text ]]" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"eg 3 - multi-level nesting " & @CRLF & _
"" & @CRLF & _
" [[ any text or no text [[ any text or no text [[ any text or no text ]] any text or no text]] any text or no text ]]" & @CRLF & _
"" & @CRLF & _
"Note: keep in mind that the double square brackets could be touching. So example 1 could also manifest as" & @CRLF & _
"" & @CRLF & _
" [[ any text or no text [[ any text ]]]]"
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