Brendan Brendan - 2 years ago 76
Python Question

How to evaluate a matched number later in a regex? - Lexing FORTRAN 'H' edit descriptor with Ply

I am using Ply to interpret a FORTRAN format string. I am having trouble writing a regex to match the 'H' edit descriptor which is of the form

xHccccc ...

where x specifies the number of characters to read in after the 'H'

Ply matches tokens with a single regular expression, but I am having trouble using regular expression to perform the above. I am looking for something like,


is parsed as an integer and evaluated as part of the regex - however it isn't.

It seems that it is not possible to use matched numbers later in the same regex, is this the case?

Does anyone have any other solutions that might use Ply?

Answer Source

Regex can't do things like that. You can hack it though:



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download