// 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; using System.Text.RegularExpressions; class MainClass { private static ArrayList valid = new ArrayList(new string[] { "b", "i" }); public static void Test(string s) { MatchCollection res1 = Regex.Matches(s, "(?:<)([^/>][^>]*)(?:>)"); for(int i = 0; i < res1.Count; i++) { if(!valid.Contains(res1[i].Groups[1].Value)) { Console.WriteLine(s + " - contains invalid start tag"); } } MatchCollection res2 = Regex.Matches(s, "(?:]+)(?:>)"); for(int i = 0; i < res2.Count; i++) { if(!valid.Contains(res2[i].Groups[1].Value)) { Console.WriteLine(s + " - contains invalid end tag"); } } } public static void Main(string[] args) { Test("Dette her er OK text"); Test("Dette her link er ikke OK"); } }