I want to make a regular expression to match a string like :
Function_Name ( 'parameters' ) Function Description
so I get the name, parameters and description.
I want to make a regular expression to match a string like :
Function_Name ( 'parameters' ) Function Description
so I get the name, parameters and description.
Assuming parameters are seperated by ,
Following PCRE regular expression should work for you.
(\w+)\s+\(([^\)]+)\s+(.+)
Subgroup 1 > function name
Subgroup 2 > parameters
Subgroup 3 > function description
If you are using AutoIt, as the tags suggest, the pattern should be a PCRE.
(\w+)\s*\(\s*([^)]+)\s*\)\s*(.+)
This is a slightly modified version of the pattern Shiplu suggested. It has optional spaces so they don't end up in the match and the same goes for the closing parentheses. There is also no need to escape the parentheses inside a character set.
(
start capturing group 1\w+
match one or more word characters (alphanumeric and underscore))
close capturing group 1\s*
match zero or more whitespace characters\(
match an opening parantheses\s*
match zero or more whitespace characters(
start capturing group 2[^)]+
match one or more characters that are not a closing parentheses )
close capturing group 2\s*
match zero or more whitespace characters\)
match a closing parentheses\s*
match zero or more whitespace characters(
start capturing group 3.+
match one or more characters that are not a whitespace)
end capturing group 3I am writing Python Regex, but I don't think it would be hard at all to pass it to PHP or Perl.
My guess would be something like this, but I am uncertain on the second .*
, if it will capture correctly the EOL or not.
(\w+)\s\(\s'\s(.+)\s'\s\)\s(.*)