#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)(?:(self|parent|selfOrParent)|(?:(prevSibling|ancestor|selfOrAncestor)((?:#[\w-]+)?(?:\.[\w-]+)*)))\[(?:(id|ref)|(?:data)-([\w-]+))\]"
Local $sString = "self[id]" & @CRLF & _
"self[data-key]" & @CRLF & _
"self[ref]" & @CRLF & _
"parent[id]" & @CRLF & _
"parent[data-key]" & @CRLF & _
"parent[ref]" & @CRLF & _
"selfOrParent[id]" & @CRLF & _
"selfOrParent[data-key]" & @CRLF & _
"selfOrParent[ref]" & @CRLF & _
"" & @CRLF & _
"prevSibling[id]" & @CRLF & _
"prevSibling[data-key]" & @CRLF & _
"prevSibling[ref]" & @CRLF & _
"prevSibling#id[id]" & @CRLF & _
"prevSibling#id[data-key]" & @CRLF & _
"prevSibling#id[ref]" & @CRLF & _
"" & @CRLF & _
"ancestor[id]" & @CRLF & _
"ancestor#anId[id]" & @CRLF & _
"ancestor#anId.class[id]" & @CRLF & _
"ancestor#anId.class.class[id]" & @CRLF & _
"ancestor.class[id]" & @CRLF & _
"ancestor.class.class[id]" & @CRLF & _
"" & @CRLF & _
"ancestor[data-key]" & @CRLF & _
"ancestor#anId[data-key]" & @CRLF & _
"ancestor#anId.class[data-key]" & @CRLF & _
"ancestor#anId.class.class[data-key]" & @CRLF & _
"ancestor.class[data-key]" & @CRLF & _
"ancestor.class.class[data-key]" & @CRLF & _
"" & @CRLF & _
"ancestor[ref]" & @CRLF & _
"ancestor#anId[ref]" & @CRLF & _
"ancestor#anId.class[ref]" & @CRLF & _
"ancestor#anId.class.class[ref]" & @CRLF & _
"ancestor.class[ref]" & @CRLF & _
"ancestor.class.class[ref]" & @CRLF & _
"" & @CRLF & _
"selfOrAncestor[id]" & @CRLF & _
"selfOrAncestor#anId[id]" & @CRLF & _
"selfOrAncestor#anId.class[id]" & @CRLF & _
"selfOrAncestor#anId.class.class[id]" & @CRLF & _
"selfOrAncestor.class[id]" & @CRLF & _
"selfOrAncestor.class.class[id]" & @CRLF & _
"" & @CRLF & _
"selfOrAncestor[data-key]" & @CRLF & _
"selfOrAncestor#anId[data-key]" & @CRLF & _
"selfOrAncestor#anId.class[data-key]" & @CRLF & _
"selfOrAncestor#anId.class.class[data-key]" & @CRLF & _
"selfOrAncestor.class[data-key]" & @CRLF & _
"selfOrAncestor.class.class[data-key]" & @CRLF & _
"" & @CRLF & _
"selfOrAncestor[ref]" & @CRLF & _
"selfOrAncestor#anId[ref]" & @CRLF & _
"selfOrAncestor#anId.class[ref]" & @CRLF & _
"selfOrAncestor#anId.class.class[ref]" & @CRLF & _
"selfOrAncestor.class[ref]" & @CRLF & _
"selfOrAncestor.class.class[ref]" & @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