[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string patterns
- From: Andreas Stenius <andreas@...>
- Date: Thu, 11 Jan 2007 11:32:08 +0100
Luiz Henrique de Figueiredo skrev:
No, not alternates like that, simply to be able to:
foo:gsub("(.-)[%s$]", bar)
Then try foo:gsub("(.-)%s?$", bar).
Yes, but this will make the capture greedy.. what saved me was that when
I read the source in lstrlib.c I found the frontiers: %f[...] which
saved me by simply appending a space at the end of my subject.
What made this more problematic was that I wanted to match
[[name=value name2='other val' name3="no, should I match this as well!"]]
where the value MIGHT be enclosed in single OR double quotes, and with
quotes, there may be spaces between the quotes too ;o).
So my pattern I successfully use now isn't pretty:
-- snippet is part of a bigger function
local function parseargs()
local t = {}
;(args .. " "):gsub("(%w+)%s*=%s*([\"']?)(.-)%2%f[%s]",
function( k, _, v )
t[k:lower()] = v
return ""
end)
return t
end
--
Med vänlig hälsning,
Andreas Stenius
_________________________________
Boxcom AB
E-post: andreas@boxcom.se
Tel: 08-550 330 50
Fax: 08-550 330 52
Mobil: 070-442 22 50
Web: www.boxcom.se
Virkesvägen 10, 152 42 Södertälje
Automatiska körjournaler - IT-Tjänster
Med en dosa i bilen får du koll på milen!
begin:vcard
fn:Andreas Stenius
n:Stenius;Andreas
org:Boxcom AB
adr;quoted-printable;quoted-printable:;;Virkesv=C3=A4gen 10;S=C3=B6dert=C3=A4lje;;15242;Sweden
email;internet:andreas@boxcom.se
tel;work:08-550 330 50
tel;fax:08-550 330 52
tel;cell:070-44 22 250
url:http://www.boxcom.se
version:2.1
end:vcard