// 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.Text.RegularExpressions; class MainClass { public static void Main(string[] args) { string inputString = "bla bla a http://www.test.com bla bla bla bla"; Regex r = new Regex("(http://[^ ]*)|(src\\s*=\\s*\"(http://[^\"]*)\")",RegexOptions.IgnoreCase|RegexOptions.Compiled); for (Match m = r.Match(inputString); m.Success; m = m.NextMatch()) { if(m.Groups[1].Value != "") Console.WriteLine("htmllink found:" + m.Groups[1]); if(m.Groups[3].Value != "") Console.WriteLine("imgsrc found:" + m.Groups[3]); } } }