By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,346 Members | 2,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,346 IT Pros & Developers. It's quick & easy.

Search replace using Regular Expression

P: 1
I am trying to create a regular expression that will search a memo and replace all values that are between "[]" brackets. Example:

static void Main()
{
string text = @"This is a memo for: [employeeName]. From: [supervisorsName]. This is inregards to [trainingType]\n"
+ " on [Date].";
string pattern = "I NEED THIS INFORMTION";
MatchCollection matches = Regex.Matches(text, pattern,
RegexOptions.IgnoreCase);
WriteMatches(text, matches);
}

static void WriteMatches(string text, MatchCollection matches)
{
Console.WriteLine("Original text was: \n\n" + text + "\n");
Console.WriteLine("No. of matches: " + matches.Count);
foreach (Match nextMatch in matches)
{
Console.WriteLine(nextMatch.ToString());
}

Please any help would be appreciated
Aug 7 '08 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 427
hi,

this will return "[text between brackets]"

Expand|Select|Wrap|Line Numbers
  1. string pattern = "\\[.*\\]";
Aug 12 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.