lua-users home
lua-l archive

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

> Now I guess technically .* matches an empty string, so one could argue that
> it would make an infinite number of replacements.

To avoid this infinite loop, the scanner advances one position after
matching an empty string (several other pattern-matching machines addopt
a similar solution). This a safeguard, not a feature. In other words,
avoid the use of patterns that match the empty string.

> However, given that it says it matches the longest possible string in the
> docs, I would've expected to get a single substitution, not 2.

The first substitution is "string" (the longest possible string starting
at position 1); the next is "" (the longest possible string starting at
position 7, where the previous substitution stopped).

-- Roberto