A RegEx question

  • Thread starter Thread starter Bob Altman
  • Start date Start date
B

Bob Altman

Hi,

Can some kind RegEx guru give me some help? I want to parse an expression
of the form:

EXECUTE func [param [,param...]]

In other words, the expression begins with "PARAM" followed by whitespace
and func, optionally followed by whitespace and one or more comma-delimited
parameters (where the first parameter is not preceded by a comma).

My question is, how do I construct a RegEx expression and evaluate it so
that I can iterate through the zero or more "param" strings contained in the
expression?

Thanks!

- Bob
 
My question is, how do I construct a RegEx expression and evaluate it so
that I can iterate through the zero or more "param" strings contained in
the expression?

One option would be to match the entire param list in one RegExp and then
use String::Split or RegExp::Split to break that apart.

Good luck,

-Derek
 
Never mind, I figured it out. The following code parses the string
contained in a text box and displays the relevant fields:

Dim re As New Regex( _

"^(exec|execute)\s+(?<proc>\w+)(\s+(?<param1>\w+)(\s*,\s*(?<param>\w+))*)?",
_
RegexOptions.IgnoreCase)

Dim m As Match = re.Match(TextBox1.Text)
If m.Success Then
Debug.WriteLine("Proc: " & m.Groups("proc").Value)
Debug.WriteLine("Param1: " & m.Groups("param1").Value)
For Each c As Capture In m.Groups("param").Captures
Debug.WriteLine("param: " & c.Value)
Next
End If
 
Back
Top