#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m).*def[\s\\]*?(\w+)[\s\\]*?\(([\w\W]*?)\)(?:[\s\\]*?->[\s\\]*?([\w\(\)\[\]\,]+))?[\s\\]*?:"
Local $sString = "def foo():" & @CRLF & _
"def foo()->None:" & @CRLF & _
"def foo()->None :" & @CRLF & _
"def foo()-> None :" & @CRLF & _
"def foo()-> tuple[None,None] :" & @CRLF & _
"def foo()->tuple[None,None]:" & @CRLF & _
"def foo()->tuple[None,None] :" & @CRLF & _
"def foo()-> tuple[None,None]:" & @CRLF & _
"def foo()-> (None,) :" & @CRLF & _
"def foo()->(None,) :" & @CRLF & _
"def foo()-> (None,):" & @CRLF & _
"def foo()->(None,):" & @CRLF & _
"def _foo():" & @CRLF & _
"def _123foo():" & @CRLF & _
"def _123foo__():" & @CRLF & _
"def _123foo__24():" & @CRLF & _
"def foo(x):" & @CRLF & _
"def foo(x,y):" & @CRLF & _
"def foo(x:int):" & @CRLF & _
"def foo(x:int,y:float):" & @CRLF & _
"def foo(x:int,y:float)->None:" & @CRLF & _
"def foo(x:int,y:float) ->None:" & @CRLF & _
"def foo(x:int,y:float) -> None:" & @CRLF & _
"def \" & @CRLF & _
" foo\" & @CRLF & _
" (x:int,y:float)->None" & @CRLF & _
" :" & @CRLF & _
"def foo(func : Callable[[int,int],\" & @CRLF & _
" int]):"
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