← GalleryGolang function metadata parsing✨ Emoji Combos/(?x)^
(?<StatementDesc>(?:
(?:
[\/\/].+(?=\n)\n)*
)*
)
(?:
(?:
# Begin Function Declaration
func[[:space:]]+
# Datatype Method?
(?:
\(
(?<funcRecvrVar>[a-zA-Z_]+)
[[:space:]]+
(?<funcRecvrTypePointerChar>\*?)
(?<funcRecvrType>[^[[:space:]\)]+)
(?<funcRecvrErr>.*?(?=[\)]))
\)
)?
[[:space:]]*
# Function Name
(?<funcName>[a-zA-Z]+)
[[:space:]]*
# Parameters
\((?<funcParamBody>
# <funcParam> is optional
(?<funcParam>
(?<funcParam1>
(?<funcParam1Name>
[A-Za-z_\d]+
(?:
[[:space:]]+
(?<funcParam1Type>
[A-Za-z_\d]+
[[:space:]]*
)?
|
[[:space:]]*
)?
)
)
# Next Parameter recursion
(?:
# Check if comma
(?=,)[,]
[[:space:]]*
(?<funcParam2>
(?<funcParam2Name>
[A-Za-z_\d]+
(?:
[[:space:]]+
(?<funcParam2Type>
[A-Za-z_\d]+
[[:space:]]*
)?
|
[[:space:]]*
)?
)
)
# Next Parameter recursion
(?:
# Check if comma
(?=,)[,]
[[:space:]]*
(?<funcParam3>
(?<funcParam3Name>
[A-Za-z_\d]+
(?:
[[:space:]]+
(?<funcParam3Type>
[A-Za-z_\d]+
[[:space:]]*
)?
|
[[:space:]]*
)?
)
)
)?
)?
(?<funcParamRest>[^\)]*)
)?
)\)
[[:space:]]*
# Return Value
(?:
# Return inside parens
(?:[\(]
(?<funcReturn1>[^\),[:space:]]+)
(?:
[[:space:]]*[,][[:space:]]*
(?<funcReturn2>[^\),[:space:]]+)
(?:
[[:space:]]*[,][[:space:]]*
(?<funcReturn3>[^\),[:space:]]+)
)?
)?
[\)]
)
|
# Single Return Outside Parens
(?<funcReturnSingle>[^\{[:space:]]+)
|
)?
[[:space:]]*
[[:space:]]*
)
# Remove Non-relevant lines
(?<removed>
(?:
# At new line, check if its blank || begins with spaces or not `func`
(?=
(?:
$
|
[[:space:]\t].+\n
|
(?!\/\/|func)
)
)
.+\n+(?=(?![\/]|func))
)+
)?
)/gmixXPCRE+06 years ago✓ Pre-loaded
About this regex
Parses Go function declarations to extract structured metadata including receiver info (for methods), function name, parameters (up to 3 named plus rest), and return values. It also captures preceding single-line comments as documentation and skips irrelevant lines. Useful for code analysis tools, documentation generators, or building AST-like representations from Go source code.