[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua idiom for RE-style alternation?
- From: Scott Vokes <vokes.s@...>
- Date: Wed, 6 Jan 2010 17:04:37 -0500
> What is "Lua idiom" -- using the regular string library, not lpeg or any
> of the RE add-ons -- when doing string matching with alternative
> strings in it. For example, something like this:
> "eat (green|yellow)? (bananas|apples) daily"
Someone please correct me if I'm wrong, but I'm pretty sure this
isn't possible with the standard string library. The ?, *, and -
operators work for individual characters or character classes, but not
sequences of characters.
You could run over a list of patterns with the individual keywords
filled in (using format or gsub), though that would involve a test for
each permutation of keywords. I'd just use LPEG, but that may not be
an option in your case.
Scott