fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. 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.";
  9. const string regexPattern = @"\b(?:EMP(?:id|[s:#])?\s+(?<EMPid>\d{1,11})|(?<EMPurl>https?://emps/\d+))(?!\S)";
  10. var search = new Regex(regexPattern , RegexOptions.IgnoreCase);
  11. MatchCollection matches = search.Matches(sourceText);
  12.  
  13. foreach (Match match in matches)
  14. {
  15. Console.WriteLine(match.Value.ToString());
  16. }
  17. }
  18. }
Success #stdin #stdout 0.07s 21508KB
stdin
Standard input is empty
stdout
EMP 1234
EMP 4567
http://emps/2345