Yet another RE question

Christos TZOTZIOY Georgiou tzot at sil-tec.gr
Sat Jan 10 12:33:16 EST 2004


On Sat, 10 Jan 2004 10:36:07 +0200, rumours say that "Bogdan Marinescu"
<bogdanal at b.astral.ro> might have written:

[snip: this is about a simple compiler of a small language, and Python
follows Perl re symantics instead of POSIX: a|ab always matches 'a' even
if 'ab' would match in the search string]

>This is quite annoying for me; while some solutions to this problem exists and they are shown in the Spark documentation, I have some background with lex/yacc and I would really like to use the "lex" semantics (longest match). Is there a package for Python that implements this behaviour?

AFAIK no, there is no such package.  However, you can do the following
things:

- reorder alternations (sp?) to be longest first

Substitute "ab|a" for "a|ab"

- the (?!...) operator might help

The re "if(?![a-z_0-9])" would match the 'if' and would ignore all
identifiers starting with 'if'.

HTH.
-- 
TZOTZIOY, I speak England very best,
Ils sont fous ces Redmontains! --Harddix



More information about the Python-list mailing list