Regular Expression

Q

quest

I have a regular expression :

Match match = Regex.Match(line, @"(?<name>.*)\((?<id>\S+)\)");

It is able to parse the text with the following syntax:
data(Hello)
type(integer)

My regular expression failed when the following is encountered:

data(Hello world)

How do I modify my regular expression to make it work for the above as well
? The goal is to have everything enclosed in the bracket to be extracted.
Thanks.
 
N

Nicolas Guinet

Hi,

string rex = @"(?<name>.*)\((?<id>.*)\)";
string test = "data(Hello World, how are you)";

Match match = Regex.Match(test, rex); //,
RegexOptions.Singleline|RegexOptions.IgnoreCase);

if (match != Match.Empty)
{
textBox1.Text += "Function Name is '" + match.Groups["name"].Value +
"'\r\n";
textBox1.Text += "Argument is '" + match.Groups["id"].Value + "'";
}
else
{
textBox1.Text = "Erreur";
}


Nicolas Guinet
 

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