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 recordRepresents a choice between multiple alternative regex patterns.static enumRepresents an anchor, which matches a position like start or end of a line.static final recordRepresents a quantifier with a minimum bound, like{min,},*, or+.static final recordRepresents a quantifier with a maximum bound and a minimum of 0, like{0,max}or?.static interfaceRepresents a character property, like\p{Lower}or\P{Lower}.static interfaceRepresents a custom character class, like[a-z]or[^0-9].static final recordRepresents a range of characters within a character class, e.g., 'a-z'.static interfaceBase interface for elements within aRegexPattern.CharacterSet.static interfaceRepresents a grouping construct in a regex.static final recordRepresents a quantifier with both minimum and maximum bounds, like{n}or{min,max}.static final recordRepresents a literal string to be matched.static final recordRepresents a single literal character within a character class.static interfaceRepresents a lookaround assertion:(?=...),(?!...),(?<=...),(?<!...).static enumRepresents a POSIX character class inside a CharacterSet: e.g.static enumRepresents a predefined character class like\dor\w.static final recordRepresents a regex pattern that is modified by a quantifier.static interfaceBase interface for all quantifier types.static final recordRepresents a sequence of regex patterns that must match consecutively.static final recordRepresents a Unicode property class: e.g. -
Method Summary
Modifier and TypeMethodDescriptionstatic RegexPattern.Alternationalternation(RegexPattern... alternatives) Returns anRegexPattern.Alternationof the given alternatives.anyOf(RegexPattern.CharSetElement... elements) Returns aRegexPattern.CharacterSetof the given elements.anyOf(Collection<? extends RegexPattern.CharSetElement> elements) Returns aRegexPattern.CharacterSetof the given elements.static Collector<RegexPattern, ?, RegexPattern> A collector that collects the inputRegexPatternas an alternation.default RegexPatternfollowedBy(RegexPattern suffix) Returns a pattern that matchesthisonly if it is followed bysuffix.static Collector<RegexPattern, ?, RegexPattern> A collector that collects the inputRegexPatternas a sequence.noneOf(RegexPattern.CharSetElement... elements) Returns a negatedRegexPattern.CharacterSetof the given elements.noneOf(Collection<? extends RegexPattern.CharSetElement> elements) Returns a negatedRegexPattern.CharacterSetof the given elements.default RegexPatternnotFollowedBy(RegexPattern suffix) Returns a pattern that matchesthisonly if it is NOT followed bysuffix.default RegexPatternnotPrecededBy(RegexPattern prefix) Returns a pattern that matchesthisonly if it is NOT preceded byprefix.static RegexPatternParses the given regular expression string and returns itsRegexPatternrepresentation.default RegexPatternprecededBy(RegexPattern prefix) Returns a pattern that matchesthisonly if it is preceded byprefix.static RegexPattern.Sequencesequence(RegexPattern... elements) Returns aRegexPattern.Sequenceof the given elements.
-
Method Details
-
sequence
Returns aRegexPattern.Sequenceof the given elements. -
inSequence
A collector that collects the inputRegexPatternas a sequence. Nested sequences are flattened and adjacent literals are concatenated as a single literal. -
alternation
Returns anRegexPattern.Alternationof the given alternatives. -
asAlternation
A collector that collects the inputRegexPatternas an alternation. -
anyOf
Returns aRegexPattern.CharacterSetof the given elements. -
anyOf
static RegexPattern.CharacterSet.AnyOf anyOf(Collection<? extends RegexPattern.CharSetElement> elements) Returns aRegexPattern.CharacterSetof the given elements. -
noneOf
@SafeVarargs static RegexPattern.CharacterSet.NoneOf noneOf(RegexPattern.CharSetElement... elements) Returns a negatedRegexPattern.CharacterSetof the given elements. -
noneOf
static RegexPattern.CharacterSet.NoneOf noneOf(Collection<? extends RegexPattern.CharSetElement> elements) Returns a negatedRegexPattern.CharacterSetof the given elements. -
precededBy
Returns a pattern that matchesthisonly if it is preceded byprefix. Equivalent to(?<=prefix)this. -
followedBy
Returns a pattern that matchesthisonly if it is followed bysuffix. Equivalent tothis(?=suffix). -
notPrecededBy
Returns a pattern that matchesthisonly if it is NOT preceded byprefix. Equivalent to(?<!prefix)this. -
notFollowedBy
Returns a pattern that matchesthisonly if it is NOT followed bysuffix. Equivalent tothis(?!suffix). -
parse
Parses the given regular expression string and returns itsRegexPatternrepresentation.- Throws:
Parser.ParseException- if the regex pattern is malformedIllegalArgumentException- if the regex pattern is invalid
-