M
mikekimhome
I am trying to capture a whole function definition from a file. I have
read the contents of the file into a string variable and tried a regex
to extract the function definition. Good thing is I already know the
function signature. For example, i have a string
variable(sFileContents) that holds the following contents and I already
know what I am looking for is function body for "function Foo(byval a
as integer)"
---- start of the content---------
Dim objRS, SQL
Dim sChannel
function Foo(byval a as integer)
' do something
dim c as integer
if a > 0 then
exit function
c = a + a
Foo = c
end function
' something else .....
---- end of the content---------
I tried the following but no avail. please help!!
Dim oRegex As Regex
Dim oMatch As Match
oRegex = New Regex((?<result>(function Foo\(byval a as
integer\))(\w+)function$), RegexOptions.IgnoreCase Or
RegexOptions.Compiled)
oMatch = oRegex.Match(sFileContents)
If oMatch.Success Then
sFuncBody = oMatch.Groups("result").ToString()
End If
read the contents of the file into a string variable and tried a regex
to extract the function definition. Good thing is I already know the
function signature. For example, i have a string
variable(sFileContents) that holds the following contents and I already
know what I am looking for is function body for "function Foo(byval a
as integer)"
---- start of the content---------
Dim objRS, SQL
Dim sChannel
function Foo(byval a as integer)
' do something
dim c as integer
if a > 0 then
exit function
c = a + a
Foo = c
end function
' something else .....
---- end of the content---------
I tried the following but no avail. please help!!
Dim oRegex As Regex
Dim oMatch As Match
oRegex = New Regex((?<result>(function Foo\(byval a as
integer\))(\w+)function$), RegexOptions.IgnoreCase Or
RegexOptions.Compiled)
oMatch = oRegex.Match(sFileContents)
If oMatch.Success Then
sFuncBody = oMatch.Groups("result").ToString()
End If