fork(18) download
  1. #include <iostream>
  2. #include <regex>
  3. #include <vector>
  4.  
  5. int main() {
  6. std::regex rx(R"(^([+-]?(?:[[:d:]]+\.?|[[:d:]]*\.[[:d:]]+))(?:[Ee][+-]?[[:d:]]+)?$)");
  7. std::vector<std::string> v({{
  8. "1", "0", "10",
  9. "1000.1", "+1",
  10. "+10", "-10", "1.",
  11. ".1", "1.1", "+1.",
  12. "-1.", "+.1", "-.1",
  13. "009", "+009", "-009",
  14. "-01e0", "+01E0", "+1e-1",
  15. "+1e+1", "+1.e1", "1E1",
  16. "1E+1", "0.001e-12", "0.111111111111111",
  17. ".", "1a", "++1",
  18. "+-1", "+", "-.",
  19. "-", "--1.", "1.e.1",
  20. "1e.1", "0+.e0"
  21. }});
  22. for (int i = 0; i < v.size(); ++i) {
  23. std::cout << (std::regex_match(v[i], rx) ? "matched: " : "not matched: ")
  24. << v[i] << std::endl;
  25. }
  26.  
  27. // std::regex rx2(R"(^[[:alpha:]][[:alnum:]]*$)");
  28. // std::string s("ыwwe3");
  29. // if (std::regex_match(s, rx2)) {
  30. // std::cout << "var object matched\n";
  31. // }
  32. return 0;
  33. }
Success #stdin #stdout 0s 15336KB
stdin
Standard input is empty
stdout
matched: 1
matched: 0
matched: 10
matched: 1000.1
matched: +1
matched: +10
matched: -10
matched: 1.
matched: .1
matched: 1.1
matched: +1.
matched: -1.
matched: +.1
matched: -.1
matched: 009
matched: +009
matched: -009
matched: -01e0
matched: +01E0
matched: +1e-1
matched: +1e+1
matched: +1.e1
matched: 1E1
matched: 1E+1
matched: 0.001e-12
matched: 0.111111111111111
not matched: .
not matched: 1a
not matched: ++1
not matched: +-1
not matched: +
not matched: -.
not matched: -
not matched: --1.
not matched: 1.e.1
not matched: 1e.1
not matched: 0+.e0