[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: order of matches for string.gsub
- From: Gunnar Zötl <gz@...>
- Date: Fri, 21 Jul 2023 14:52:33 +0200
Hi there,
here's something I stumbled across. The documentation of string.gmatch()
kinda implies that the matches are done in order from the beginning to
the end of the string. It is not outright stated, but the documentation
says that the iterator returned by string.gmatch() returns the next
captures ... each time it is called.
However, for string.gsub(), there is no such implication. It talks about
each occurrence of pattern being substituted by (whatever) in the
returned sting. There is no mention of the order in which that happens.
Of course, when you try it with sth like string.gsub("abc", ".", print),
you will see the matches from beginning to end.
Sooo, as string.gsub is a mighty tool which has quite a few applications
when working with strings, I would really like to know whether there is
any guarantee (outside of observed behaviour) that this is always the case.
Regards,
Gunnar