#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?mxsJ)(?<katex_all>" & @CRLF & _
" (?:" & @CRLF & _
" (?<!\\|\$)" & @CRLF & _
" (?<katex_open>" & @CRLF & _
" \${2}" & @CRLF & _
" |" & @CRLF & _
" \${1}" & @CRLF & _
" )" & @CRLF & _
" (?!\$)" & @CRLF & _
" \n?" & @CRLF & _
" (?<katex_content>.+?)\n?" & @CRLF & _
" (?<!\\|\$)" & @CRLF & _
" (?<katex_close>\g{katex_open})" & @CRLF & _
" (?!\$)" & @CRLF & _
" \n?" & @CRLF & _
" )" & @CRLF & _
" |" & @CRLF & _
" (?:" & @CRLF & _
" (?<!\\)" & @CRLF & _
" (?<katex_open>\\\[)" & @CRLF & _
" \n?" & @CRLF & _
" (?<katex_content>.+?)\n?" & @CRLF & _
" (?<!\\)" & @CRLF & _
" (?<katex_close>" & @CRLF & _
" \\\]" & @CRLF & _
" )\n?" & @CRLF & _
" )" & @CRLF & _
" |" & @CRLF & _
" (?:" & @CRLF & _
" (?<!\\)" & @CRLF & _
" (?<katex_open>\\\()" & @CRLF & _
" \n?" & @CRLF & _
" (?<katex_content>.+?)\n?" & @CRLF & _
" (?<!\\)" & @CRLF & _
" (?<katex_close>" & @CRLF & _
" \\\)" & @CRLF & _
" )\n?" & @CRLF & _
" )" & @CRLF & _
")"
Local $sString = "$$" & @CRLF & _
"\Gamma(z) = \int_0^\infty t^{z-1}e^{-t}dt\,." & @CRLF & _
"$$" & @CRLF & _
"" & @CRLF & _
"This is some text $math \frac12$" & @CRLF & _
"" & @CRLF & _
"other text $\unsupported$" & @CRLF & _
"" & @CRLF & _
"Other node \[ displaymath \\[\\] \frac{1}{2} \] blah" & @CRLF & _
"" & @CRLF & _
"$$ \int_2^3 $$" & @CRLF & _
"" & @CRLF & _
"more text \(and math\) blah" & @CRLF & _
"" & @CRLF & _
"And $math with a" & @CRLF & _
" \$ sign$." & @CRLF & _
"" & @CRLF & _
"This should not match↓" & @CRLF & _
"$$$" & @CRLF & _
"\Gamma(z) = \int_0^\infty t^{z-1}e^{-t}dt\,." & @CRLF & _
"$$$" & @CRLF & _
"" & @CRLF & _
"This should not match either" & @CRLF & _
"$$" & @CRLF & _
"\Gamma(z) = \int_0^\infty t^{z-1}e^{-t}dt\,." & @CRLF & _
"$" & @CRLF & _
""
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH)
Local $aFullArray[0]
For $i = 0 To UBound($aArray) -1
_ArrayConcatenate($aFullArray, $aArray[$i])
Next
$aArray = $aFullArray
; Present the entire match result
_ArrayDisplay($aArray, "Result")
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