Interface RegexPattern
- All Known Subinterfaces:
RegexPattern.CharacterProperty
,RegexPattern.CharacterSet
,RegexPattern.Group
,RegexPattern.Lookaround
- All Known Implementing Classes:
RegexPattern.Alternation
,RegexPattern.Anchor
,RegexPattern.CharacterProperty.Negated
,RegexPattern.CharacterSet.AnyOf
,RegexPattern.CharacterSet.NoneOf
,RegexPattern.Group.Capturing
,RegexPattern.Group.Named
,RegexPattern.Group.NonCapturing
,RegexPattern.Literal
,RegexPattern.Lookaround.Lookahead
,RegexPattern.Lookaround.Lookbehind
,RegexPattern.Lookaround.NegativeLookahead
,RegexPattern.Lookaround.NegativeLookbehind
,RegexPattern.PosixCharClass
,RegexPattern.PredefinedCharClass
,RegexPattern.Quantified
,RegexPattern.Sequence
,RegexPattern.UnicodeProperty
public sealed interface RegexPattern
permits RegexPattern.Alternation, RegexPattern.Sequence, RegexPattern.Quantified, RegexPattern.Group, RegexPattern.Literal, RegexPattern.PredefinedCharClass, RegexPattern.CharacterProperty, RegexPattern.CharacterProperty.Negated, RegexPattern.CharacterSet, RegexPattern.Anchor, RegexPattern.Lookaround
Defines the Abstract Syntax Tree (AST) for a regular expression.
This AST is used to represent parsed regular expressions, as a basis to enable static analysis of regexes.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final record
Represents a choice between multiple alternative regex patterns.static enum
Represents an anchor, which matches a position like start or end of a line.static final record
Represents a quantifier with a minimum bound, like{min,}
,*
, or+
.static final record
Represents a quantifier with a maximum bound and a minimum of 0, like{0,max}
or?
.static interface
Represents a character property, like\p{Lower}
or\P{Lower}
.static interface
Represents a custom character class, like[a-z]
or[^0-9]
.static final record
Represents a range of characters within a character class, e.g., 'a-z'.static interface
Base interface for elements within aRegexPattern.CharacterSet
.static interface
Represents a grouping construct in a regex.static final record
Represents a quantifier with both minimum and maximum bounds, like{n}
or{min,max}
.static final record
Represents a literal string to be matched.static final record
Represents a single literal character within a character class.static interface
Represents a lookaround assertion:(?=...)
,(?!...)
,(?<=...)
,(?<!...)
.static enum
Represents a POSIX character class inside a CharacterSet: e.g.static enum
Represents a predefined character class like\d
or\w
.static final record
Represents a regex pattern that is modified by a quantifier.static interface
Base interface for all quantifier types.static final record
Represents a sequence of regex patterns that must match consecutively.static final record
Represents a Unicode property class: e.g. -
Method Summary
Modifier and TypeMethodDescriptionstatic RegexPattern.Alternation
alternation
(RegexPattern... alternatives) Returns anRegexPattern.Alternation
of the given alternatives.anyOf
(RegexPattern.CharSetElement... elements) Returns aRegexPattern.CharacterSet
of the given elements.anyOf
(Collection<? extends RegexPattern.CharSetElement> elements) Returns aRegexPattern.CharacterSet
of the given elements.static Collector
<RegexPattern, ?, RegexPattern> A collector that collects the inputRegexPattern
as an alternation.default RegexPattern
followedBy
(RegexPattern suffix) Returns a pattern that matchesthis
only if it is followed bysuffix
.static Collector
<RegexPattern, ?, RegexPattern> A collector that collects the inputRegexPattern
as a sequence.noneOf
(RegexPattern.CharSetElement... elements) Returns a negatedRegexPattern.CharacterSet
of the given elements.noneOf
(Collection<? extends RegexPattern.CharSetElement> elements) Returns a negatedRegexPattern.CharacterSet
of the given elements.default RegexPattern
notFollowedBy
(RegexPattern suffix) Returns a pattern that matchesthis
only if it is NOT followed bysuffix
.default RegexPattern
notPrecededBy
(RegexPattern prefix) Returns a pattern that matchesthis
only if it is NOT preceded byprefix
.static RegexPattern
Parses the given regular expression string and returns itsRegexPattern
representation.default RegexPattern
precededBy
(RegexPattern prefix) Returns a pattern that matchesthis
only if it is preceded byprefix
.static RegexPattern.Sequence
sequence
(RegexPattern... elements) Returns aRegexPattern.Sequence
of the given elements.
-
Method Details
-
sequence
Returns aRegexPattern.Sequence
of the given elements. -
inSequence
A collector that collects the inputRegexPattern
as a sequence. Nested sequences are flattened and adjacent literals are concatenated as a single literal. -
alternation
Returns anRegexPattern.Alternation
of the given alternatives. -
asAlternation
A collector that collects the inputRegexPattern
as an alternation. -
anyOf
Returns aRegexPattern.CharacterSet
of the given elements. -
anyOf
static RegexPattern.CharacterSet.AnyOf anyOf(Collection<? extends RegexPattern.CharSetElement> elements) Returns aRegexPattern.CharacterSet
of the given elements. -
noneOf
@SafeVarargs static RegexPattern.CharacterSet.NoneOf noneOf(RegexPattern.CharSetElement... elements) Returns a negatedRegexPattern.CharacterSet
of the given elements. -
noneOf
static RegexPattern.CharacterSet.NoneOf noneOf(Collection<? extends RegexPattern.CharSetElement> elements) Returns a negatedRegexPattern.CharacterSet
of the given elements. -
precededBy
Returns a pattern that matchesthis
only if it is preceded byprefix
. Equivalent to(?<=prefix)this
. -
followedBy
Returns a pattern that matchesthis
only if it is followed bysuffix
. Equivalent tothis(?=suffix)
. -
notPrecededBy
Returns a pattern that matchesthis
only if it is NOT preceded byprefix
. Equivalent to(?<!prefix)this
. -
notFollowedBy
Returns a pattern that matchesthis
only if it is NOT followed bysuffix
. Equivalent tothis(?!suffix)
. -
parse
Parses the given regular expression string and returns itsRegexPattern
representation.- Throws:
Parser.ParseException
- if the regex pattern is malformedIllegalArgumentException
- if the regex pattern is invalid
-