fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4. using namespace std;
  5.  
  6. int main() {
  7. string a[2] = {"this string contains integer 1423 and character", "100"} ;
  8. regex integer("(\\+|-)?[[:digit:]]+");
  9.  
  10. for (int i=0; i < sizeof(a)/sizeof(string); i++) {
  11. if (regex_match(a[i], integer)) {
  12. cout << a[i] << ": contains integer only\n";
  13. } else {
  14. cout << a[i] << ": doesn't contain integer only\n";
  15. }
  16. }
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 3496KB
stdin
Standard input is empty
stdout
this string contains integer 1423 and character: doesn't contain integer only
100: contains integer only