lua-users home
lua-l archive

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


Hi Steve
As per your suggestion, I tried a small test script as looks below.


function calculate_content_length1(msg, length)
    local lens = msg:match('^Content%-Length%s*:%s+(%d+)%s+$')
    if lens then -- gotcha Content-length
       len = tonumber(lens)
       print(lens)
    else
    print('pattern not found')
    end
end

msg = "INVITE\r\nContent-Length              : 100      \r\n\r\nv=0\r\n"
calculate_content_length1(msg, string.len(msg))


It prints pattern not found.

What may be the probable reason?

Regards
Austin




On Mon, Jul 7, 2014 at 2:03 PM, steve donovan <steve.j.donovan@gmail.com> wrote:
On Mon, Jul 7, 2014 at 9:18 AM, Austin Einter <austin.einter@gmail.com> wrote:
> Please note that, input string might have some data before or after of given
> example values.

How about something really simple?

local lens = input:match('^Content%-Length%s*:%s+(%d+)%s+$')
if lens then -- gotcha Content-length
   len = tonumber(lens)
end

Note how '-' must be escaped...%s matches all whitespace, including line ends.