(https://www.inf.puc-rio.br/~roberto/lpeg/re.html).
Pattern:match({subject}, {init}, {...}) *Pattern:match()*
Matches the given `pattern` against the `subject` string. If the match
succeeds, returns the index in the subject of the first character after
the match, or the captured values (if the pattern captured any value). An
optional numeric argument `init` makes the match start at that position in
the subject string. As usual in Lua libraries, a negative value counts
from the end. Unlike typical pattern-matching functions, `match` works
only in anchored mode; that is, it tries to match the pattern with a
prefix of the given subject string (at position `init`), not with an
arbitrary substring of the subject. So, if we want to find a pattern
anywhere in a string, we must either write a loop in Lua or write a
pattern that matches anywhere.
Example: >lua
local pattern = lpeg.R('az') ^ 1 * -1
assert(pattern:match('hello') == 6)
assert(lpeg.match(pattern, 'hello') == 6)
assert(pattern:match('1 hello') == nil)
<
Parameters: ~
• {subject} (`string`)
• {init} (`integer?`)
• {...} (`any`)
Return: ~
(`any`) ...
vim.lpeg.B({pattern}) *vim.lpeg.B()*
Returns a pattern that matches only if the input string at the current
position is preceded by `patt`. Pattern `patt` must match only strings
with some fixed length, and it cannot contain captures. Like the `and`
predicate, this pattern never consumes any input, independently of success
or failure.
Parameters: ~
• {pattern} (`vim.lpeg.Pattern|string|integer|boolean|table`)
Return: ~
(`vim.lpeg.Pattern`)
vim.lpeg.C({patt}) *vim.lpeg.C()*
Creates a simple capture, which captures the substring of the subject that
matches `patt`. The captured value is a string. If `patt` has other
captures, their values are returned after this one.
Example: >lua
local function split (s, sep)
sep = lpeg.P(sep)
local elem = lpeg.C((1 - sep) ^ 0)
local p = elem * (sep * elem) ^ 0
return lpeg.match(p, s)
end
local a, b, c = split('a,b,c', ',')
assert(a == 'a')
assert(b == 'b')
assert(c == 'c')
<
Parameters: ~
• {patt} (`vim.lpeg.Pattern|string|integer|boolean|table|function`)
Return: ~
(`vim.lpeg.Capture`)
vim.lpeg.Carg({n}) *vim.lpeg.Carg()*
Creates an argument capture. This pattern matches the empty string and
produces the value given as the nth extra argument given in the call to
`lpeg.match`.
Parameters: ~
• {n} (`integer`)
Return: ~
(`vim.lpeg.Capture`)
vim.lpeg.Cb({name}) *vim.lpeg.Cb()*
Creates a back capture. This pattern matches the empty string and produces
the values produced by the most recent group capture named `name` (where
`name` can be any Lua value). Most recent means the last complete
outermost group capture with the given name. A Complete capture means that
the entire pattern corresponding to the capture has matched. An Outermost
capture means that the capture is not inside another complete capture. In
the same way that LPeg does not specify when it evaluates captures, it
does not specify whether it reuses values previously produced by the group
or re-evaluates them.
Parameters: ~
• {name} (`any`)
Return: ~
(`vim.lpeg.Capture`)
vim.lpeg.Cc({...}) *vim.lpeg.Cc()*
Creates a constant capture. This pattern matches the empty string and
produces all given values as its captured values.
Parameters: ~
• {...} (`any`)
Return: ~
(`vim.lpeg.Capture`)