// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Text.RegularExpressions; namespace E { public class Program { private static readonly Regex re = new Regex(@"^\$(\w+)(\((.*)\))?\$$", RegexOptions.Compiled); private static void Parse(string s, List res) { if(re.IsMatch(s)) { Match m = re.Match(s); res.Add(m.Groups[1].Value); if(m.Groups[3].Value != "") Parse(m.Groups[3].Value, res); } else { res.Add(s); } } public static List Parse(string s) { List res = new List(); Parse(s, res); return res; } public static void Main(string[] args) { string[] sa = new string[] { "$DATE$", "$DATE(5)$", "$UPPER('some string')$", "$DATE($DATE$)$", "$DATE($TIME(5)$)$" }; foreach(string s in sa) { Console.Write(s + " ->"); foreach(string e in Parse(s)) Console.Write(" " + e); Console.WriteLine(); } } } }