fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string[] inputstrings = new string[] { "Total Hours Worked (.5);", "Total Hours Worked (.A);", "Total Hours Worked (A);" };//Collection of inputs.
  9. Regex rgx = new Regex(@"\(\.?(?<StringValue>[a-zA-Z]*)\)\;{1}");//Regular expression to find all matches.
  10. foreach (string input in inputstrings)//Iterate through each string in collection.
  11. {
  12. Match match = rgx.Match(input);
  13. if (match.Success)//If a match is found.
  14. {
  15. string value = match.Groups[1].Value;//Capture first named group.
  16. Console.WriteLine(value);//Display captured substring.
  17. }
  18. else//If nothing is found.
  19. {
  20. Console.WriteLine("A match was not found.");
  21. }
  22. }
  23. }
Compilation error #stdin compilation error #stdout 0.07s 34200KB
stdin
Standard input is empty
compilation info
prog.cs(23,1): error CS1525: Unexpected symbol `end-of-file'
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty