lua-users home
lua-l archive

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


On 13.06.2011 15:26, Peter Cawley wrote:
On Mon, Jun 13, 2011 at 12:23 PM, Xavier Wang<weasley.wx@gmail.com>  wrote:
local s = "abcdef"
print(string.match(s, "(^abc)(def$)"))
shows "nil"
but:
local s = "abcdef"
print(string.match(s, "^(abc)(def)$"))
shows "abc def"
is this behavior correct?

According to the manual, yes:

A '^' at the beginning of a pattern anchors the match at the beginning
of the subject string. A '$' at the end of a pattern anchors the match
at the end of the subject string. At other positions, '^' and '$' have
no special meaning and represent themselves.


that's not standard regexp interpretation.

[~]>perl -e "print 'abcdef' =~ /^(abc)(def)$/"
abcdef
>perl -e "print 'abcdef' =~ /(^abc)(def$)/"
abcdef