Is there a maximum length of a regular expression in python?
Roy Smith
roy at panix.com
Wed Jan 18 09:21:52 EST 2006
In article <1137591911.333364.221990 at z14g2000cwz.googlegroups.com>,
olekristianvillabo at gmail.com wrote:
> I have a regular expression that is approximately 100k bytes. (It is
> basically a list of all known norwegian postal numbers and the
> corresponding place with | in between. I know this is not the intended
> use for regular expressions, but it should nonetheless work.
>
> the pattern is
> ur'(N-|NO-)?(5259 HJELLESTAD|4026 STAVANGER|4027 STAVANGER........|8305
> SVOLVÆR)'
>
> The error message I get is:
> RuntimeError: internal error in regular expression engine
I don't know of any stated maximum length, but I'm not at all surprised
this causes the regex compiler to blow up. This is clearly a case of regex
being the wrong tool for the job.
I'm guessing a dictionary, with the numeric codes as keys and the city
names as values (or perhaps the other way around) is what you want.
More information about the Python-list
mailing list