fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Example
  5. {
  6. public static void Main()
  7. {
  8. string pattern = @"^Name:\s*(\S+)\s*$";
  9. string input = @"Name: John
  10. Name: Jane
  11. Name: Mary
  12.  
  13. a sentence here with name in it would be fine. ";
  14. RegexOptions options = RegexOptions.Multiline;
  15.  
  16. foreach (Match m in Regex.Matches(input, pattern, options))
  17. {
  18. Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
  19. }
  20. }
  21. }
Success #stdin #stdout 0.05s 21168KB
stdin
Standard input is empty
stdout
'Name: John' found at index 0.
'Name: Jane  ' found at index 11.
'Name: Mary 
' found at index 24.