lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


With the pattern '(/.-/)$', you're asking Lua to match a forward
slash, then match as few characters as possible such that what then
follows is a forward slash followed by the end of the string. After
the first forward slash in the pattern is matched against the first
forward slash in the input, the minimum amount which can be captured
to get a forward slash followed by the end of the input is the entire
of the input.

On Fri, Oct 30, 2009 at 8:43 PM, Joshua Jensen
<jjensen@workspacewhiz.com> wrote:
> I ran into this today, and while I tried to explain it away, I have to admit
> I am mildly confused.
>
> Why does the following match the entire string "/dev/myprog/image/xyz/"?
>
> =string.match('/dev/myprog/image/xyz/', '(/.-/)$)
>
> The documentation states that a - (minus) matches the shortest possible
> sequence.
>
> I hadn't given this any thought until today, as I normally would have
> written '.+(/.-/)$'.  That would have yielded the correct result of '/xyz/'.
>   When discussing it with a coworker, though, he raised the point that with
> the final / (slash) anchored at the end of the string, the shortest possible
> matching sequence should be '/xyz/'.
>
> I can buy into that argument.  What are we missing?
>
> Thanks!
>
> Josh
>