fork(19) download
  1. #include <regex>
  2. #include <string>
  3. #include <iostream>
  4. #include <time.h>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. struct tm tm;
  10. time_t t;
  11. string data("On 2015-12-23, the shop will be closed, but on 2016-01-03, it will be open. Invalid date: 2016-13-32. ID: 1022015-12-233333.");
  12. std::regex pattern("\\b\\d{4}[-]\\d{2}[-]\\d{2}\\b");
  13. std::smatch result;
  14.  
  15. while (regex_search(data, result, pattern)) {
  16. if (strptime(result[0].str().c_str(), "%Y-%m-%d", &tm) != NULL) {
  17. std::cout << result[0] << std::endl;
  18. }
  19. data = result.suffix().str();
  20. }
  21. }
Success #stdin #stdout 0s 3544KB
stdin
Standard input is empty
stdout
2015-12-23
2016-01-03