[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: gsub strangeness
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 29 Aug 2002 09:07:53 -0300
> 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).