lua-users home
lua-l archive

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


It worked fine. Thanks Pierre-Yves Gérardy andThijs Schreijer.
Austin


On Wed, Jun 25, 2014 at 4:17 PM, Pierre-Yves Gérardy <pygy79@gmail.com> wrote:
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?