#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)^(?<![\s\S\r])(---\ntitle:\s)([1-9a-zA-ZÀ-ŰØ-űø-ÿ].*)([\d\D]*---\n\n#\s[1-9a-zA-ZÀ-ŰØ-űø-ÿ].*)"
Local $sString = "---" & @CRLF & _
"title: Title can be anything" & @CRLF & _
"aliases:" & @CRLF & _
" - somealias" & @CRLF & _
"tags:" & @CRLF & _
" - sometag" & @CRLF & _
"topic: sometopic" & @CRLF & _
"anotheryamlKey: whatever" & @CRLF & _
"date created: 2022-12-14" & @CRLF & _
"date modified: 2023-10-06" & @CRLF & _
"---" & @CRLF & _
"" & @CRLF & _
"# Title can be anything" & @CRLF & _
"" & @CRLF & _
"First line of file. " & @CRLF & _
"Second line. "
Local $sSubst = "$1$2$3\n\n%%\n```query\nfile: "$2.md" /\\[\\[(?!.*\\|)([^[\\]]+#[^\\]]+)\\]\\]/\n```\n%%"
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