Posted by Anonymous on Thu 28 Aug 15:17
report abuse | download | new post
- using System;
- using System.Text.RegularExpressions;
- namespace myapp
- {
- class Class1
- {
- static void Main(string[] args)
- {
- String sourcestring = @"[[Text:hi this is a nice sentence[[very nice]] I like this text]] this is not related [[not]]";
- MatchCollection mc = re.Matches(sourcestring);
- // to iterate through the matches and catpure groups
- int mIdx = 0;
- foreach (Match m in mc)
- {
- for (int gIdx = 0; gIdx < m.Groups.Count; gIdx++)
- {
- Console.WriteLine("[" + mIdx + "][" + re.GetGroupNames()[gIdx] + "] = " + m.Groups[gIdx].Value);
- }
- mIdx++;
- }
- // to iterate through the [[Text:... matches only
- foreach (Match m in mc)
- {
- if (m.Groups[0].Value.Substring(0, 7) == "[[Text:")
- {
- Console.WriteLine(m.Groups[0].Value);
- }
- }
- }
- }
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.