#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(^|\s)#[a-zA-Z0-9][\w-]*\b"
Local $sString = "#Beginning of string matches," & @CRLF & _
"" & @CRLF & _
"#Word matches." & @CRLF & _
"" & @CRLF & _
"#word_1 and #word-1 matches." & @CRLF & _
"" & @CRLF & _
"They match even if they are followed by a non-word like #word" or #word" or #word." & @CRLF & _
"" & @CRLF & _
"#_words beggining width underscore or with #-hypen don't match." & @CRLF & _
"" & @CRLF & _
"Brok#en words don't match either." & @CRLF & _
"" & @CRLF & _
"Should we match these cases? -#word "#word ,#word" & @CRLF & _
"" & @CRLF & _
"Hash from urls do not match: http://site/#hash" & @CRLF & _
"" & @CRLF & _
"Neither ?#hash nor -#hash" & @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