Pattern

Methods
9
Fields
9

Getting one

Pattern.compile(…)
Pattern.compile(…):matcher(…):pattern()

Methods

MethodReturnsDescription
matcher(string)MatcherA matcher of this pattern over input.
find(string)booleanAlternative to p:matcher(s):find(): a one-call search with no Matcher object. Whether this pattern matches anywhere in input: `p:find…
split(string){string}(Pattern, string) -> {string}: input split around matches, trailing empty strings removed (a 1-based array).
split(string, number){string}
pattern()stringThe source regular expression.
toString()stringThe source regular expression.
flags()numberThe flags: those it was compiled with, and those a top-level inline group turned on or off ((?i)a answers CASE_INSENSITIVE; (?i:a) do…
compile(string)Pattern(string) -> Pattern: Compile regex.
compile(string, number)Pattern
quote(string)stringA pattern matching s literally: \Q + s + \E, with any \E in s escaped.
matches(string, string)booleanWhether regex matches the whole of input.

Fields

FieldTypeDescription
UNIX_LINESnumberPattern's flag bit.
CASE_INSENSITIVEnumberPattern's flag bit.
COMMENTSnumberPattern's flag bit.
MULTILINEnumberPattern's flag bit.
LITERALnumberPattern's flag bit.
DOTALLnumberPattern's flag bit.
UNICODE_CASEnumberPattern's flag bit.
CANON_EQnumberPattern.CANON_EQ's bit. Bento does not implement canonical equivalence: a pattern compiled with it raises.
UNICODE_CHARACTER_CLASSnumberPattern's flag bit.

Returned by

MethodReturnsDescription
Matcher.patternPatternThe pattern: the very Pattern it was made from (or last given to usePattern).
PatternClass.compilePattern(string) -> Pattern: Compile regex.

Method details

find

find: (Pattern, string) -> boolean

Alternative to p:matcher(s):find(): a one-call search with no Matcher object. Whether this pattern matches anywhere in input: p:find(s) answers what p:matcher(s):find() answers, without making the matcher, for a filter that only asks whether a line matches (a chat filter, a hidden-item list). For the match's position or groups, use matcher.

split

split: ((Pattern, string) -> {string}) & ((Pattern, string, number) -> {string})

(Pattern, string) -> {string}: input split around matches, trailing empty strings removed (a 1-based array).

(Pattern, string, number) -> {string}: input split around matches: at most limit pieces when positive, every piece when negative, trailing empty strings removed when 0 (or nil).

flags

flags: (Pattern) -> number

The flags: those it was compiled with, and those a top-level inline group turned on or off ((?i)a answers CASE_INSENSITIVE; (?i:a) does not).

compile

compile: ((string) -> Pattern) & ((string, number) -> Pattern)

(string) -> Pattern: Compile regex.

(string, number) -> Pattern: Compile regex with flags (Pattern.CASE_INSENSITIVE, ... or'ed).

quote

quote: (string) -> string

A pattern matching s literally: \Q + s + \E, with any \E in s escaped.

matches

matches: (string, string) -> boolean

Whether regex matches the whole of input.