How do I use regular expressions with Standard Template Library in C++?

I am trying to learn regular expressions in C++. I need to have it so that the user can only enter in the integers between 1 & 15. Can someone show me an example in code?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
#include <regex>
#include <iostream>
#include <string>

int main()
{
    std::regex number("^(1[0-5]|[0-9])$");
    std::string input;
    std::cin >> input;
    std::cout << "your input is " << (std::regex_match(input, number)?
                                      "valid":"not valid\n");
}
Topic archived. No new replies allowed.