I'm trying to do some input validation for a time in the format
"1:00 to 12:59 and AM/PM"
I created this regex:\b((1[0-2]|0?[1-9]):([0-5][0-9]) *([AaPp][Mm]))
. I tested it at regexr.com and it worked fine.
However, when I try to do something like:
std::string s ("1:00 AM");
std::regex e ("\b((1[0-2]|0?[1-9]):([0-5][0-9]) *([AaPp][Mm]))");
if (std::regex_match (s,e))
std::cout << "string object matched\n";
It never works. Any idea what I might be doing wrong?
Thanks to @MYGz I was able to fix this. Maybe it had something to do with escape characters.
All I did to change @MYGz's suggestion was to remove the \s.
It worked with ([0-1]?[0-2]:[0-5][0-9] *[AaPp][Mm])
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments