[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Stack overflow in regexp matcher
From: |
Ilya Zakharevich |
Subject: |
Re: Stack overflow in regexp matcher |
Date: |
Thu, 17 Dec 2009 22:10:55 +0000 (UTC) |
User-agent: |
slrn/0.9.8.1pl1 (Linux) |
On 2009-12-17, Barry Margolin <barmar@alum.mit.edu> wrote:
>> A function of mine gets "Stack overflow in regexp matcher" on a certain
>> file using the regexp
>>
>> "^< \\(.+].+=|\\)"
> The problem is that + is greedy, so this has to scan the entire line
> looking for the last "]", then see if there's an "=" somewhere later.
> If it can't find an "=" it has to back up to the previous "]" and search
> again, and so on. If there are lots of "]" characters, this has to save
> the state of each of them in the matching stack.
What for? There is no need to keep state of unsuccessful matches...
So the "next-]" state should replace the older one.
Yours,
Ilya