#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?Jx)(?<sub_all>" & @CRLF & _
" (?:" & @CRLF & _
" (?<!\\)\~" & @CRLF & _
" (?<sub_text>" & @CRLF & _
" (?>\\[\~[:blank:]\h]|[^\~[:blank:]\h\v])*+" & @CRLF & _
" )" & @CRLF & _
" (?<!\\)\~" & @CRLF & _
" )" & @CRLF & _
" |" & @CRLF & _
" (?: # or the Microsoft way. Beurk" & @CRLF & _
" \<sub\>" & @CRLF & _
" (?<sub_text>" & @CRLF & _
" ((?!\v).)+" & @CRLF & _
" )" & @CRLF & _
" \<\/sub\>" & @CRLF & _
" )" & @CRLF & _
")"
Local $sString = "log~10~100 is 2." & @CRLF & _
"" & @CRLF & _
"Space is not allowed:" & @CRLF & _
"P~a cat~" & @CRLF & _
"" & @CRLF & _
"But it's ok if it is escaped" & @CRLF & _
"P~a\ cat~" & @CRLF & _
"" & @CRLF & _
"Line break is a no-no, even escaped" & @CRLF & _
"P~a\" & @CRLF & _
" cat~" & @CRLF & _
"" & @CRLF & _
"Hmm <sub>This is a Microsoft subscript!</sub>" & @CRLF & _
"" & @CRLF & _
"H~2~0" & @CRLF & _
"" & @CRLF & _
"text~a\ superscript~" & @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