[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: multiline rex.match
- From: Shmuel Zeigerman <shmuz@...>
- Date: Fri, 17 Dec 2010 10:03:06 +0200
Philippe Lhoste wrote:
OK. I just downloaded the lib and opened the manual, but found this
topic on flags a bit obscure (from a quick scan at least).
At least the fact they are listed (in match() ref. for example) as
numbers with bitwise OR... A quick look at the tests didn't help either.
The "compilation flags" in Lrexlib can be specified in either of two
ways: as a number (for _any_ flag or flag combination), or as a string
(only for a subset of flags). Note 6 in the manual lists this subset for
PCRE and Oniguruma bindings. Here are 2 equivalent examples (PCRE
binding is assumed):
-- Example 1: compilation flags as a number:
local F = rex.flags()
local cf = bit.bor(F.CASELESS, F.MULTILINE, F.EXTENDED)
-- ( "PCRE_" prefix must be omitted )
-- Example 2: compilation flags as a string:
local cf = "imx" -- same flags as in example 1
-- The call:
local c1 [, c2 ...] = rex.match(subject, pattern, offset, cf)
Yehuda Eisenstark wrote:
I read the manual.txt file for lrexlib-2.5.3, but am still a bit confused. Can you point me to an example of using the 'm' flag as the 4th parameter and of using ?m in the pattern?
The 'm' flag as the 4th parameter to rex.match can be specified either
as F.MULTILINE or as "m" (see the examples above).
Embedding flags in the pattern is described in the PCRE docs. It works
in Oniguruma, too. It is not an Lrexlib feature.
Here's a simple example:
print(rex.match("aBcD", "abcd")) --> nil
print(rex.match("aBcD", "(?i)abcd")) --> aBcD