fork download
  1. #include <iostream>
  2. #include <regex>
  3. #include <string>
  4.  
  5. int main(int argc, char *argv[]) {
  6. std::regex base_regex("[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?");
  7.  
  8. for (const auto& s : {"email@subdomain.domain.com",
  9. "Invalid email@subdomain.domain.com",
  10. "a@c.c.c.ccb.c",
  11. "a@c.c.cc.ccb.c",
  12. "a@c.cc.c.ccb.c",
  13. "a@cc.c.c.ccb.c"
  14. })
  15. {
  16. std::cout << s << " : " << (std::regex_match(s, base_regex) ? "Found" : "Not found") << std::endl;
  17. }
  18.  
  19. }
Success #stdin #stdout 0s 3496KB
stdin
Standard input is empty
stdout
email@subdomain.domain.com : Found
Invalid email@subdomain.domain.com : Not found
a@c.c.c.ccb.c : Found
a@c.c.cc.ccb.c : Found
a@c.cc.c.ccb.c : Found
a@cc.c.c.ccb.c : Found