fork download
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4. %}
  5.  
  6. %%
  7.  
  8. ^[+]?[0-9]{1,4}[\s-]?[0-9]{10}$ {
  9. printf("Valid Mobile Number: %s\n", yytext);
  10. }
  11.  
  12. [a-zA-Z_][a-zA-Z0-9_]* {
  13. printf("Valid Identifier: %s\n", yytext);
  14. }
  15.  
  16. ^(https?|ftp):\/\/[^\s\/$.?#].[^\s]*$ {
  17. printf("Valid URL: %s\n", yytext);
  18. }
  19.  
  20. ^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[0-2])\/[0-9]{4}$ {
  21. printf("Valid Date: %s\n", yytext);
  22. }
  23.  
  24. ^(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$ {
  25. printf("Valid Time: %s\n", yytext);
  26. }
  27.  
  28. .|\n { /* Ignore other inputs */ }
  29.  
  30. %%
  31.  
  32. int main() {
  33. printf("Enter text to validate (Ctrl+D to end):\n");
  34. yylex();
  35. return 0;
  36. }
  37.  
Success #stdin #stdout #stderr 0.02s 6976KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/Vhf8Qs/prog:36:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit