[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: patternsize(p), finding the min & max length of substring matched by pattern p
- From: Duncan Cross <duncan.cross@...>
- Date: Sat, 14 Jan 2012 16:12:29 +0000
On Sat, Jan 14, 2012 at 3:59 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2012/1/14 Duncan Cross <duncan.cross@gmail.com>:
>> Hi List,
>>
>> I recently had a case where I wanted to find the maximum and minimum
>> number of characters that can be matched by a given Lua string
>> pattern, as used by string.match() etc.
>>
>> I couldn't find any existing implementation, so here's mine. It's
>> pretty simple, but I'd be interested to know if anyone can see a case
>> that it would give the wrong answer for, or any other critique.
>>
>
>
> p=".-."
> print(patternsize(p))
> 1 nil
>
Ah. Yes. When "non-greedy" becomes "eternally-starving".
-Duncan