lundi 11 septembre 2023

std::regex in c++11 the preceding token is not quantifiable

When using std::regex in c++11 I encounter some errors. Below I have shown the error

  {Unknown expression after the reported line}
due to unexpected exception with message:
  Invalid special open parenthesis.

I am trying to write a regular expression but I can't get it work for all the below mentioned cases

Here is my regex

\btmax\s*(\[(.*?((?:[^\[\]]+?|(\1))*)\]))

which when used with

tSunset = tmin[idx] + (tmax[idx] - tmin[idx]) * sin((M_PI * daylength[i])/(daylength[i] + 4.0));

correctly returns idx

However, when I used the expression

\bprec\s*(\[(.*?((?:[^\[\]]+?|(\1))*)\]))

with the following string

prec[season_idx[j] + i * 12];

I get j, though I expect to get season_idx[j] + 1 * 12.

I am using this with std::regex in c++11 so I am limited to ECMAScript. If I use regex compatible with PCRE like the following

\bprec\s*(\[(.*?((?:[^\[\]]+?|(?1))*)\]))

I get the correct response

season_idx[j] + i * 12

Aucun commentaire:

Enregistrer un commentaire