class Pattern
😱 Types incomplete or incorrect? 🙏 Please contribute!
methods
Pattern.match
Match 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.
This second approach is easy and quite efficient;
Example: