fork(2) download
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <regex.h>
  5. int main ()
  6. {
  7. char * str = "<sql db=../serverTcp/Testing.db query=SELECT * From BuyMarsians;\\>";
  8. char * regex = "<sql\\s+db=(.+?)\\s+query=(.+;)\\s*\\\\>";
  9. regex_t regexCompiled;
  10.  
  11. if (regcomp(&regexCompiled,regex,REG_EXTENDED))
  12. {
  13. printf("Could not compile regular expression.\n");
  14. fflush(stdout);
  15. }
  16. else {
  17. printf("Compiled successfully!\n");
  18. fflush(stdout);
  19. }
  20. if (!regexec(&regexCompiled,str, 0, NULL, 0)) {
  21. printf("matched\n");
  22. fflush(stdout);
  23. }
  24. else {
  25. printf("no match; return value was %d\n", regexec(&regexCompiled,str, 0, NULL, 0));
  26. fflush(stdout);
  27. }
  28. regfree(&regexCompiled);
  29. return 0;
  30. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Compiled successfully!
matched