using System; using System.Text.RegularExpressions; public class Test { public static void Main() { string sourceText = "This will contain a bunch of text. Might also contain EMP 1234 and there could be a bunch of text after this pattern. There could again be EMP 4567 or http://emps/2345 We'll be extracting all such patterns. 3 in this case."; const string regexPattern = @"\b(?:EMP(?:id|[s:#])?\s+(?\d{1,11})|(?https?://emps/\d+))(?!\S)"; var search = new Regex(regexPattern , RegexOptions.IgnoreCase); MatchCollection matches = search.Matches(sourceText); foreach (Match match in matches) { Console.WriteLine(match.Value.ToString()); } } }