I want to match expression of the pattern
a space followed by a (addition operator or subtraction operator)
For example:
" +"
should return True
I have tried the using std::regex_match
on the following regular exp:
" [+-]"
, "\\s[+-]"
, "\\s[+\\-]"
, "\\s[\\+-]"
but they all return false.
What should be the correct expression ?
EDIT
Here's the test code:
#include<iostream>
#include<string>
#include<regex>
using std::cout;
int main()
{
std::string input;
std::cin>>input;
const std::regex ex(" [\\+-]");
std::smatch m;
if( std::regex_match(input,ex))
{
cout<<"\nTrue";
}
else
cout<<"\nFalse";
return 0;
}