$re = '/(?x)(?(DEFINE)
(?<AutoItString> "(?> [^"]+ | "" )*" # double quoted string
|
\'(?> [^\']+ | \'\' )*\' # single quoted string
) # AutoIt string definition
(?<CommentBlock> (?m)
^\h*\# (?>cs|comments-start)\b # start of comment block
(?sU:(?>(?&CommentBlock)|.)*) # content of comment block (could be nested)
^\h*\#(?>ce|comments-end)\b.*\R # end of comment block
)
(?<NonComment> (?> (?&AutoItString) | [^\;\r\n])* ) # anything what\'s not a single comment
(?<SingleComment> (?m) ^ (?&NonComment)\K\;.*$) # a AutoIt single line comment
(?<Comment> (?&CommentBlock) | (?&SingleComment) ) # all AutoIt comments
(?<MultilineCmd> (?>_\h* (?>\;.*$)? [\r\n]*)+)
(?<FuncName> ([\w_]+)) # function name
(?<FuncDef> ^\h*Func(?:|\h|(?&MultilineCmd))+ (?&FuncName) (?:\h|(?&MultilineCmd))* (?=\() ) # function definition
(?<BracketContent> \( (?> (?&BracketContent) | \;.*$ | (?&AutoItString) | \h*(?&MultilineCmd) | [^\;\r\n"\'()]* )* \) )
)
(?&FuncDef)((?&BracketContent))/m';
$str = 'Func _CloseInputGUI(_Test(), _Test ( ) ) ; ENABLE $g_hMainGUI; Eingegebene Daten uebernehmen, wenn kein Fehler bei der Eingabe (IP-Adresse)
Func _
_SciTE_ShowFuncName()
Func _SciTE_ShowFuncName ()
Func _SciTE_ShowFuncName ( ";" ) ;
Func _SciTE_ShowFuncName (";");
Func _SciTE_ShowFuncName (";" _
_ ; und hier ein Kommentar
, "hier geht es weiter");
Func _SciTE_ShowFuncName()
Func _SciTE_ShowFuncName( (5+6) - (3*8))
Func _SciTE_ShowFuncName() ; () blabla
Func _SciTE_ShowFuncName(_AddComment(";" & $aComment[Random(0, 1, 1)])) ; () blabla
Func _Strip(11, "Func _SciTE_ShowFuncName(\'Das hier ist ""böse"". ;)\')")';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php