Posted: 9/11/2010
Hi friends,
I need some help regarding regex. I have a long string which contains words like this "I am (peter) smith I (want) to make a (regex)"
Now from this string I want to extract all those words which are in this format (..) i.e I need the output to be (peter),(want),(regex)
Thanks,
Peter
#region Using Directives using System; using System.Text.RegularExpressions; #endregion public class Example { static void Main() { var regex = new Regex(@"(\(.*?\))", RegexOptions.Singleline | RegexOptions.IgnoreCase); const string input = "I am (peter) smith I (want) to make a (regex)"; var matches = regex.Matches(input); foreach (var match in matches) { Console.WriteLine(match.ToString()); } Console.ReadLine(); } }
Output:
(peter)
(want)
(regex)