Sprache can do this, but you'd need to write a grammar for the whole file, as it doesn't implement "searching" for a match.
Something along these lines would parse just the function declaration - as noted above, to make your scenario work you need to add rules for modules and so on.
var identifier = (from first in Parse.Letter
from rest in Parse.LetterOrDigit.Many().Text()
select first + rest).Token();
var returnType = Parse.String("void").Or(Parse.String("int")).Token();
var functionKeyword = Parse.String("function").Token();
var endFunctionKeyword = Parse.String("endfunction").Token();
var function = from fk in functionKeyword
from rt in returnType
from functionName in identifier
from body in Parse.AnyChar.Until(endFunctionKeyword)
select functionName;
var name = function.Parse("function void main write(\"a string\") endfunction");
The variable name above will contain the string "main" (unless I've made some typos :))
Sprache is a bit more powerful than regular expressions, but doesn't require any special build-time processing. There are some tutorials on this approach linked from the Sprache homepage.