lua-users home
lua-l archive

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


On 29/08/2013 11:07 PM, Roberto Ierusalimschy wrote:
I want to parse a HTTP header string "name:value" pair. In REXX this
is quite simple with the parse instruction, "parse var line name ":"
value". In lua it seems much trickier using
the example i have "local _, _, name, value = string.find(line,
"^([^: ]+)%s*:%s*(.+)")". I understand that captures are much more
powerful but what I want is to dumb them down so there
is a lower entry level of skill required to do what is simple in
REXX. Maybe it's possible to write a parse(line,"%s : %s:) function
or something similar. It's most likely the case that I just don't
know Lua string handling well enough to grok what is the best solution.
Maybe it is a "split" function what you need?

Not really. The REXX parse instruction has templates which can tokenize on a simple pattern match or offset. Lua is much more powerful but not as easy to grok for REXX heads http://publib.boulder.ibm.com/infocenter/zos/v1r11/index.jsp?topic=/com.ibm.zos.r11.ikjc300/ikj4c31062.htm.


   http://en.wikipedia.org/wiki/String_manipulation_algorithm#split

-- Roberto