Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
(?x) .+(?:Sub|Function)\ (\w+)\( # method declaration (?: # start of parameter pattern [\w\W]*?(?<=\b) # parameter may be preceded by ByVal or Optional keywords ([a-z]\w+)+ # parameter starts with a lower case .*? # parameter may be followed by its type declaration (?:=\ ([^\,]+)){0,1} # optional parameters may be followed by default value, it is captured to be used in method call (?:,|\)) # parameter is followed by , or ) ){0,1} # end of parameter pattern (may be copy-pasted infinitely to capture all parameters) (?: # start of parameter pattern [\w\W]*?(?<=\b) # parameter may be preceded by ByVal or Optional keywords ([a-z]\w+)+ # parameter starts with a lower case .*? # parameter may be followed by its type declaration (?:=\ ([^\,]+)){0,1} # optional parameters may be followed by default value, it is captured to be used in method call (?:,|\)) # parameter is followed by , or ) ){0,1} # end of parameter pattern (may be copy-pasted infinitely to capture all parameters) (?: # start of parameter pattern [\w\W]*?(?<=\b) # parameter may be preceded by ByVal or Optional keywords ([a-z]\w+)+ # parameter starts with a lower case .*? # parameter may be followed by its type declaration (?:=\ ([^\,]+)){0,1} # optional parameters may be followed by default value, it is captured to be used in method call (?:,|\)) # parameter is followed by , or ) ){0,1} # end of parameter pattern (may be copy-pasted infinitely to capture all parameters) (?: # start of parameter pattern [\w\W]*?(?<=\b) # parameter may be preceded by ByVal or Optional keywords ([a-z]\w+)+ # parameter starts with a lower case .*? # parameter may be followed by its type declaration (?:=\ ([^\,]+)){0,1} # optional parameters may be followed by default value, it is captured to be used in method call (?:,|\)) # parameter is followed by , or ) ){0,1} # end of parameter pattern (may be copy-pasted infinitely to capture all parameters) (?: # start of parameter pattern [\w\W]*?(?<=\b) # parameter may be preceded by ByVal or Optional keywords ([a-z]\w+)+ # parameter starts with a lower case .*? # parameter may be followed by its type declaration (?:=\ ([^\,]+)){0,1} # optional parameters may be followed by default value, it is captured to be used in method call (?:,|\)) # parameter is followed by , or ) ){0,1} # end of parameter pattern (may be copy-pasted infinitely to capture all parameters) (?: # start of parameter pattern [\w\W]*?(?<=\b) # parameter may be preceded by ByVal or Optional keywords ([a-z]\w+)+ # parameter starts with a lower case .*? # parameter may be followed by its type declaration (?:=\ ([^\,]+)){0,1} # optional parameters may be followed by default value, it is captured to be used in method call (?:,|\)) # parameter is followed by , or ) ){0,1} # end of parameter pattern (may be copy-pasted infinitely to capture all parameters) (?: # start of parameter pattern [\w\W]*?(?<=\b) # parameter may be preceded by ByVal or Optional keywords ([a-z]\w+)+ # parameter starts with a lower case .*? # parameter may be followed by its type declaration (?:=\ ([^\,]+)){0,1} # optional parameters may be followed by default value, it is captured to be used in method call (?:,|\)) # parameter is followed by , or ) ){0,1} # end of parameter pattern (may be copy-pasted infinitely to capture all parameters) (?: # start of parameter pattern [\w\W]*?(?<=\b) # parameter may be preceded by ByVal or Optional keywords ([a-z]\w+)+ # parameter starts with a lower case .*? # parameter may be followed by its type declaration (?:=\ ([^\,]+)){0,1} # optional parameters may be followed by default value, it is captured to be used in method call (?:,|\)) # parameter is followed by , or ) ){0,1} # end of parameter pattern (may be copy-pasted infinitely to capture all parameters) (?: # start of parameter pattern [\w\W]*?(?<=\b) # parameter may be preceded by ByVal or Optional keywords ([a-z]\w+)+ # parameter starts with a lower case .*? # parameter may be followed by its type declaration (?:=\ ([^\,]+)){0,1} # optional parameters may be followed by default value, it is captured to be used in method call (?:,|\)) # parameter is followed by , or ) ){0,1} # end of parameter pattern (may be copy-pasted infinitely to capture all parameters) (?: # start of parameter pattern [\w\W]*?(?<=\b) # parameter may be preceded by ByVal or Optional keywords ([a-z]\w+)+ # parameter starts with a lower case .*? # parameter may be followed by its type declaration (?:=\ ([^\,]+)){0,1} # optional parameters may be followed by default value, it is captured to be used in method call (?:,|\)) # parameter is followed by , or ) ){0,1} # end of parameter pattern (may be copy-pasted infinitely to capture all parameters) (?: # start of parameter pattern [\w\W]*?(?<=\b) # parameter may be preceded by ByVal or Optional keywords ([a-z]\w+)+ # parameter starts with a lower case .*? # parameter may be followed by its type declaration (?:=\ ([^\,]+)){0,1} # optional parameters may be followed by default value, it is captured to be used in method call (?:,|\)) # parameter is followed by , or ) ){0,1} # end of parameter pattern (may be copy-pasted infinitely to capture all parameters) (?: # start of parameter pattern [\w\W]*?(?<=\b) # parameter may be preceded by ByVal or Optional keywords ([a-z]\w+)+ # parameter starts with a lower case .*? # parameter may be followed by its type declaration (?:=\ ([^\,]+)){0,1} # optional parameters may be followed by default value, it is captured to be used in method call (?:,|\)) # parameter is followed by , or ) ){0,1} # end of parameter pattern (may be copy-pasted infinitely to capture all parameters)
/
gms

Description

  • all parameters are passed by names to account for possible changes in method signature
  • default values are assigned to optional parameters
  • function and sub calls are generated
  • recrusive call is generated
Submitted by anonymous - 6 years ago