#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?mi)[-\[,:.\/]?\b(?:1\d{3}|200[0123]|\d0)(?:'?s)?\b[-\],:.\/]?"
Local $sString = "I need it to catch a date between 1000 and 2003 in these forms:" & @CRLF & _
"1975" & @CRLF & _
"1970s" & @CRLF & _
"1970's" & @CRLF & _
"1970S" & @CRLF & _
"1970'S" & @CRLF & _
"70s" & @CRLF & _
"70's" & @CRLF & _
"70S" & @CRLF & _
"70'S" & @CRLF & _
"" & @CRLF & _
"I also need it to catch certain characters on either side of the date, including" & @CRLF & _
"dashes" & @CRLF & _
"-1973-" & @CRLF & _
"brackets" & @CRLF & _
"[1973]" & @CRLF & _
"commas" & @CRLF & _
",1973," & @CRLF & _
"colons" & @CRLF & _
":1973:" & @CRLF & _
"periods" & @CRLF & _
".1973." & @CRLF & _
"slashes" & @CRLF & _
"/1973/" & @CRLF & _
"" & @CRLF & _
" - some on both sides, some on only one." & @CRLF & _
"/1973" & @CRLF & _
"or" & @CRLF & _
"1973/" & @CRLF & _
"" & @CRLF & _
"My problem is that the expression is catching other characers on either side of the date as well - +1975 gets through, for instance, as does 1970s& - letters and numbers on either side do not get through, however. I'm confused." & @CRLF & _
"" & @CRLF & _
"I think I might need some sort of limit on either side before I can state the exceptions, I'm not sure what that would look like - some kind of look back? Any help would be appreciated."
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