#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?mx)^from\s+" & @CRLF & _
"(?P<package_name>[.\w]+)\s+" & @CRLF & _
"import\s+" & @CRLF & _
"(\()?" & @CRLF & _
"(?(2)" & @CRLF & _
" (?P<object>[^()]+)\)" & @CRLF & _
" |" & @CRLF & _
" (?P<object2>(?:.+[\n\r]?)+)" & @CRLF & _
")"
Local $sString = "from .sql.base import (" & @CRLF & _
" SchemaVisitor" & @CRLF & _
" )" & @CRLF & _
"import os # ignore this import" & @CRLF & _
"from _pytest.config import (" & @CRLF & _
" main, UsageError, cmdline," & @CRLF & _
" hookspec, hookimpl" & @CRLF & _
")" & @CRLF & _
"" & @CRLF & _
"I can capture this with:" & @CRLF & _
"" & @CRLF & _
"syntax1 = re.compile(r'^ *from (?P<package>[.\w]+) +import +\(?(?P<objects>[*, \n\w]+)\)? *$'," & @CRLF & _
" flags=re.MULTILINE)" & @CRLF & _
"" & @CRLF & _
"Syntax #2 uses line continutation (if needed), and technically has no newlines within the import statement:" & @CRLF & _
"" & @CRLF & _
"from pandas import Series" & @CRLF & _
"" & @CRLF & _
"from .solvers import solve, solve_linear_system, solve_linear_system_LU, \" & @CRLF & _
" solve_undetermined_coeffs, nsolve, solve_linear, checksol, \" & @CRLF & _
" det_quick, inv_quick, check_assumptions" & @CRLF & _
"" & @CRLF & _
"from .ode import checkodesol, classify_ode, dsolve, \" & @CRLF & _
" homogeneous_order"
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