[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: help about pattern-matching
- From: steve donovan <steve.j.donovan@...>
- Date: Wed, 8 Jun 2011 09:37:15 +0200
On Wed, Jun 8, 2011 at 12:46 AM, Igor Medeiros <firstname.lastname@example.org> wrote:
> (systemScreen([1 .. 9])|systemAudio([1 .. 9]))
OK, your problem is that Lua patterns do not do alternatives like
this. So you will have to split the match into two patterns:
ok = s:match 'systemScreen%(%d%)' or s:match 'systemAudio%(%d%)'
Here %d stands for [0-9], and we've had to escape '(' which otherwise
would mean a capture.
'ok' gives the actual matched string, so if s was 'a =
systemScreen(1)' then ok would be 'systemScreen(1)' .The 'or'
operation returns the value, so that s = 'print(systemAudio(9))' will
result in ok = 'systemAudio(9)'.