const regex = /(?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))/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?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))', 'gm')
const 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"". ;)')")`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions