Regular Expression

  • Thread starter Thread starter quest
  • Start date Start date
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.
 
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
 
Back
Top