A RegEx question

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
 
D

Derek Slager

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
 
B

Bob Altman

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top