0
I am developing a C++ system that I need to get some information from a String using Regular Expression, I am using a regular expression that I used in PHP perfectly, but in C++ returns blank.
const std::string s = "{{ teste }}";
std::string r = "{{((.)+)}}";
std::regex rgx(r);
std::smatch match;
if (std::regex_search(s.begin(), s.end(), match, rgx)){
std::cout << "Number of maths: " << match.size() << "\n";
for(int i=0; i < match.size(); i++){
std::cout << "match: `" << match[i] << "`\n";
}
}
In PHP it looked like this and worked perfectly:
$print_value = '/{{((.)+)}}/';
$var_get = "{{ teste }}";
preg_match($print_value, $var_get, $matches, PREG_OFFSET_CAPTURE);
$piece = explode($formatches[0][0], $var_get);
.
.
.
What could possibly be wrong? Other expressions I use work perfectly.
Grateful from now on.
I made this modification and the result was the same. I generated this regular expression on the site regex101.com and as there worked I thought I had no key problem.
– Pedro Soares
@Pedrosoares I don’t know about C++, so I think you should check if this library doesn’t need to have the bars (
/REGEX/
) beginning, end.– Guilherme Lautert
No ah, because other Regex I made, like this <code>(@for(.*))</code> works without a bar. And with a bar a syntax error is generated.
– Pedro Soares
I solved the problem. As I was using double quotes, C++ was considering "" as an escape bar and was not passing to REGEX. I put two bars to be passed and it worked. It was like this: \{\{(.+)\}\}
– Pedro Soares
@Pedrosoares Who good :D , in fact also did not notice this.
– Guilherme Lautert
Thank you so much for your help.
– Pedro Soares