how do i find a pattern in richtextbox??

the text is like :

hello i want to {help|meet|call} you {please|come|soon}.

i want to find all such strings which have curly braces and then replace the whole string with any word from within it, RANDOMLY.

so on the click of a button the above line might become :

hello i want to help you please.
hello i want to call you soon.

i thought of using regex but iam completely blank on how to use it, also i didnt understand some tutorials on google.

this method works

Random r = new Random();
        private void butRegex_Click(object sender, EventArgs e)
            string stringWithTextIn = "hello i want to {help|meet|call} you.";
            Regex regex = new Regex(@"({.*})");
            string r = regex.Replace(stringWithTextIn, new MatchEvaluator(ReplaceMatch));
        string ReplaceMatch(Match m)
            string s = m.Value;                     // Get matched text only
            s = s.Substring(1, s.Length - 2);       // Remove '{' and '}'
            string[] parts = s.Split('|');          // Break into words
            return parts[r.Next(0,parts.Length)];   // return randow word

but it works only when there is one variation i.e for sentences like

hello i want to {help|meet|call} you.

any idea what is wrong??

6 Years
Discussion Span
Last Post by GeekByChoiCe
Dim reg As New Regex(stringWithTextIn, RegularExpressions.RegexOptions.IgnoreCase Or RegularExpressions.RegexOptions.Singleline)
		Dim _match As MatchCollection = reg.Matches("my loaded text comes here")

		If _match.Count = 0 Then Return

		For Each match As Match In _match
			'call ReplaceMatch or whatever you want 
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.