fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var pattern = @"^\$*(?:(?<v>\d{1,3})(?:,(?<v>\d{3}))*|(?<v>\d+))(?<v>\.\d+)?$";
  12. var tests = new[] {"$100", "$12,203.00", "12JAN2022"};
  13. foreach (var test in tests) {
  14. var result = string.Concat(Regex.Match(test, pattern)?
  15. .Groups["v"].Captures.Cast<Capture>().Select(x => x.Value));
  16. Console.WriteLine("{0} -> {1}", test, result.Length > 0 ? result : "No match");
  17. }
  18. }
  19. }
Success #stdin #stdout 0.08s 28920KB
stdin
Standard input is empty
stdout
$100 -> 100
$12,203.00 -> 12203.00
12JAN2022 -> No match