J'ai un regex python:C++ 11 regex confusion
\A\s* # optional whitespace at the start, then
(?P<sign>[-+]?) # an optional sign, then
(?=\d|\.\d) # lookahead for digit or .digit
(?P<num>\d*) # numerator (possibly empty)
(?: # followed by
(?:/(?P<denom>\d+))? # an optional denominator
| # or
(?:\.(?P<decimal>\d*))? # an optional fractional part
(?:E(?P<exp>[-+]?\d+))? # and optional exponent
)
\s*\Z # and optional whitespace to finish
En d'autres termes, obtenir des groupes nommés pour:
- signé/non signé | rationnel/décimal/entier | numéro | avec/sans exposant
Mais je suis confondu avec le format regex C++ 11? Comme je l'ai lu il y a peu de formats supportés, mais je reçois une exception d'analyseur regex avec celui-ci. Plus, j'ai lu que le groupe nommé n'est pas pris en charge avec C++ 11 regex. Comment avoir une expression rationnelle compatible C++ 11 qui fournit un schéma équivalent?
Merci beaucoup pour votre aide.
Rock You. Pour information, quel est le style regex que vous utilisez ici? posix? –
Non, c'est ECMAScript 5. POSIX ne supporte pas les lookaheads, et il y en a un ici, '(? = \\.? \\ d)'. –