#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)(?=^.{1,50}$)^[a-zA-Z]+([ \-'][a-zA-Z]+)*?$"
Local $sString = "5" & @CRLF & _
" -- should fail" & @CRLF & _
"foster" & @CRLF & _
" -- should match" & @CRLF & _
"foster steve" & @CRLF & _
" -- should match" & @CRLF & _
"foster-morrison" & @CRLF & _
" -- should match" & @CRLF & _
"hello" & @CRLF & _
" -- should match" & @CRLF & _
"*RKER(($(#$)#$#L$KLK#$*" & @CRLF & _
" -- should fail" & @CRLF & _
"dfkfsdkfskdfjksjfksfksjfskjfksjfskfksjfksfksfskfd" & @CRLF & _
" -- should match" & @CRLF & _
"jkddkdkdkdkdkdkdkdkdkdkdkskdldkfdlkfdfkdfkdlkdkdkdffddfdfdfdgggfgfgfggggggg" & @CRLF & _
" -- should FAIL, too long" & @CRLF & _
"jkddkdkdkdkdkdkdkdkdkdkdkskdldkfdlkfdfkdfkdlkdkdkd-ffddfdfdfdgggfgfgfgggggggd" & @CRLF & _
" -- should FAIL, too long" & @CRLF & _
"dkfkerksf------aaa-----" & @CRLF & _
" -- should fail" & @CRLF & _
"test---me" & @CRLF & _
" -- should fail" & @CRLF & _
"test'''me" & @CRLF & _
" -- fails" & @CRLF & _
"foster-mo" & @CRLF & _
" -- should match" & @CRLF & _
"f-morrison" & @CRLF & _
" -- should match" & @CRLF & _
"griffith-joiner" & @CRLF & _
" -- should match" & @CRLF & _
"test-" & @CRLF & _
" -- should fail" & @CRLF & _
"-dkd" & @CRLF & _
" -- should fail" & @CRLF & _
"d'andre" & @CRLF & _
" -- should match" & @CRLF & _
"d'andre-jordan" & @CRLF & _
" -- should match" & @CRLF & _
"jordan-d'andre-joe-b'bob" & @CRLF & _
" -- should match" & @CRLF & _
"" & @CRLF & _
"\b[a-zA-Z]+?\b :: matches a last name" & @CRLF & _
"\b[a-zA-Z]+? [a-zA-Z]+?\b :: matches a space'd last name" & @CRLF & _
"\b[a-zA-Z]+?\-[a-zA-Z]+?\b :: matches a hyphenated last name" & @CRLF & _
"\b[a-zA-Z]+?'[a-zA-Z]+?\b :: matches an apostrophie'd last name"
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