#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)\{\{.*?\}\}|\{%.*?%}"
Local $sString = "{% if statement is true %} " & @CRLF & _
"The true thing" & @CRLF & _
"{% else %}" & @CRLF & _
"the false thing" & @CRLF & _
"{% endif %} " & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"{% if {{custom_attribute.${total_spend}}} >0 %}" & @CRLF & _
"Thanks for purchasing! Here's another 10% off!" & @CRLF & _
"{% else %}" & @CRLF & _
"Buy now! Would 5% off convince you?" & @CRLF & _
"{% endif %}" & @CRLF & _
"----" & @CRLF & _
"" & @CRLF & _
"Something something {{userAttribute}} something else." & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"Hi {{ ${first_name} | default: 'Valued User' }}, thanks for using the App!" & @CRLF & _
"" & @CRLF & _
"-- note that the example had an extra right bracket:" & @CRLF & _
"{{${first_name} | capitalize | strip | default: 'friend'}}}" & @CRLF & _
"" & @CRLF & _
"{{${first_name} | capitalize | strip | default: 'friend'}}" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"-- Suggested more localization friendly method instead of "default": --" & @CRLF & _
"" & @CRLF & _
"Hello {% if ${first_name} == "" %}friend{% else %}{{${first_name}| capitalize | strip}}" & @CRLF & _
"" & @CRLF & _
"" & @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