fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string[] strings = {"-3x^2 + 4.8x + 4.0 = 0", "5x + 4 = 0", "test 5 + 4 = 0"};
  9. String pattern = @"(?:[+-]?\d+(?:\.\d+)?[a-z]\^2 [+-] )?\d+(?:\.\d+)?[a-z] [+-] \d+(?:\.\d+)? = 0";
  10. foreach (string s in strings)
  11. {
  12. if (Regex.IsMatch(s, pattern)) {
  13. Console.WriteLine("Match {0} ", s);
  14. } else {
  15. Console.WriteLine("No match: {0}", s);
  16. }
  17. }
  18. }
  19. }
Success #stdin #stdout 0.03s 134592KB
stdin
Standard input is empty
stdout
Match -3x^2 + 4.8x + 4.0 = 0 
Match 5x + 4 = 0 
No match: test 5 + 4 = 0