lua-users home
lua-l archive

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


On Wed, Jun 25, 2014 at 12:41 PM, Austin Einter <austin.einter@gmail.com> wrote:
> I am trying to find the location of a sub string in main string.
> The sub string is "Max-Forwards"

> offset = string.find(msg, "Max-Forwards")

In Lua patterns, the minus is a non-greedy version of the "*".

You can escape it with % => "Max%-Forwards", but in your case, since
you're looking for a plain string, you can use the "plain" option of
string.find:

offset = string.find(msg, "Max-Forwards", 1, true) -- subject, needle,
start position, plain?