|
|
||
|
goafteru wrote:
It is mentioned in the manual:"a single character class followed by '*', which matches 0 or more repetitions of characters in the class.These repetition items will always match the longest possible sequence;"I think the empty string after "abc" should not be matched in lua, just like in other programmes (such as: sed,gawk) .
You have a badly-written regex. I hardly ever use a '*' in an matching or substitution iterator unless its for consuming whitespace. If you are pattern-matching "something that is expected to be there", it's '+' and not '*'. If your regex is too vague, it will usually end up matching in too promiscuous a manner.
------------------ ԭʼ�ʼ� ------------------ *������:* "Patrick Donnelly"<[email protected]>; *����ʱ��:* 2009��12��27��(������) ����3:20 *�ռ���:* "Lua list"<[email protected]>; *����:* Re: A bug in pattern matching ??On Sun, Dec 27, 2009 at 12:13 AM, goafteru <[email protected]> wrote:> > print ( string.gsub("abc", "%w*", "@") ) > > and the result is: > @@ 2 > > rather than: > @ 1 %w* can match the empty string, which it does after abc matches. -- -Patrick Donnelly
-- Cheers, Kein-Hong Man (esq.) Kuala Lumpur, Malaysia