I am using RegEx to extract substrings in a RPN formula. For example with this formula:
10 2 / 3 + 7 4
I use this RegEx to extract substring (I hope it could return {"10", "2", "/", "3", "+", "7", "4"}
[0-9]+|[\/*+-])\s?
Firstly, I try it with Python:
s = r"([0-9]+|[\/*+-])\s?"
text = "10 2 / 3 + 7 4"
x = re.findall(s,text)
for i in x:
print(i)
And this is the output, as I think it is.
10
2
/
3
+
7
4
However, when I use the expression in C++:
#include <bits/stdc++.h>
#include <regex>
using namespace std;
int main(){
string text = "10 2 / 3 + 7 4";
smatch m;
regex rgx("([0-9]+|[\/*+-])\s+");
regex_search(text, m, rgx);
for (auto x : m){
cout << x << " ";
}
}
The compiler return two warnings in 7th line: unknown escape sequence: '/' and '\s' and it return nothing but several spaces.
I want to know what is the problem with my expression when I use it in C++?