#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?<=_)(\d{4})(?=_?|\.p\d)"
Local $sString = "14-5678_jobname_0123_.p1.PDF" & @CRLF & _
"14-5678_jobname_0123_.p2.PDF" & @CRLF & _
"14-5678_jobname_0125_.p1.PDF" & @CRLF & _
"Weired_filename_0123_bla_14-5678_jobname.p1.PDF" & @CRLF & _
"Weired_filename_0123_bla_14-5678_jobname.p2.PDF" & @CRLF & _
"Weired_filename_0125_bla_14-5678_jobname.p1.PDF" & @CRLF & _
"14-5678_jobname_0123.p1.PDF" & @CRLF & _
"14-5678_jobname_0123.p2.PDF" & @CRLF & _
"14-5678_jobname_0125.p1.PDF" & @CRLF & _
"0123_14-5678_jobname.p1.PDF" & @CRLF & _
"0123_14-5678_jobname.p2.PDF" & @CRLF & _
"0125_14-5678_jobname.p1.PDF" & @CRLF & _
"jobname_0123_14-5678.p1.PDF" & @CRLF & _
"jobname_0123_14-5678.p2.PDF" & @CRLF & _
"jobname_0125_14-5678.p1.PDF"
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