lua-users home
lua-l archive

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


I thought that there was a way of escaping it but couldn't work it out. Thanks for that.

On 5 Jan 2008, at 12:40 , Peter Odding wrote:

'-' has a special meaning as a pattern item. You can either escape it with %- or use the optional fourth parameter to string.find that turns off pattern matching:

> = string.find(a, '%-%-')
17      18
> = string.find(b, '%-%-')
nil
> = string.find(a, "--", 1, true)
17      18
> = string.find(b, "--", 1, true)
nil

peterhickman schreef:
I am trying to do the following:
a = 'this line has a -- comment'
b = 'this line does not'
print(string.find(a,"--"))
print(string.find(b,"--"))
but in both cases the results are
1   0
1   0
how do I match "--" in a string?
--
Fear is Money

--
Java: There is only so much you can do in a straight jacket