Package com.gengoai.string
Class Re
- java.lang.Object
-
- com.gengoai.string.Re
-
public final class Re extends Object
Commonly used Regex classes and constructs for building Patterns.
- Author:
- David B. Bracewell
-
-
Field Summary
Fields Modifier and Type Field Description static String
ANY
An unescaped period representing match anything.static String
BACKSLASH
Backlash characterstatic String
CARRIAGE_RETURN
The constant CARRIAGE_RETURN.static String
CLOSE_PUNCTUATION
Unicode close punctuationstatic String
CONNECTOR_PUNCTUATION
Unicode connector punctuationstatic String
CURRENCY_SYMBOL
Unicode currency charactersstatic String
DASH_PUNCTUATION
Unicode dash punctuationstatic String
DIGIT
Unicode digitsstatic String
ESC_BACKSLASH
Escaped backslashstatic String
FINAL_PUNCTUATION
Unicode final punctuationstatic String
FORM_FEED
The constant FORM_FEED.static String
INITIAL_PUNCTUATION
Unicode initial punctuationstatic String
LETTER
Unicode letterstatic String
LINE_FEED
The constant LINE_FEED.static String
LOWERCASE_LETTER
Unicode lowercase letterstatic String
MARK
Unicode mark characters.static String
MATH_SYMBOL
Unicode math symbolsstatic String
MODIFIER_SYMBOL
Unicode modifier symbolsstatic String
MULTIPLE_WHITESPACE
The constant MULTIPLE_WHITESPACE.static String
NON_WHITESPACE
The constant NON_WHITESPACE.static String
NUMBER
Unicode numbersstatic String
OPEN_PUNCTUATION
Unicode open punctuationstatic String
OTHER_SYMBOL
Unicode other symbolsstatic String
PUNCTUATION
Unicode punctuationstatic String
QUOTE
The quote character.static String
SYMBOL
Unicode symbol charactersstatic String
TAB
The constant TAB.static String
UNICODE_WHITESPACE
The constant UNICODE_WHITESPACE.static String
UPPERCASE_LETTER
Unicode uppercase letterstatic String
WHITESPACE
matches unicode whitespace.static String
WORD_BOUNDARY
Word boundarystatic String
ZERO_OR_MORE_WHITESPACE
The constant ZERO_OR_MORE_WHITESPACE.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
any()
Any string.static String
chars(boolean negated, @lombok.NonNull char... chars)
Converts the given array of characters into a regex character class.static String
chars(boolean negated, @NonNull CharSequence... chars)
Converts the given array of strings into a regex character class.static String
chars(char... chars)
Converts the given array of chars into a regex character class.static String
chars(String... chars)
Converts the given array of strings into a regex character class.static String
e(char character)
E string.static String
greedyOneOrMore(@NonNull CharSequence... sequence)
Greedy one or more string.static String
greedyZeroOrMore(@NonNull CharSequence... sequence)
Greedy zero or more string.static String
group(@NonNull CharSequence... sequence)
Group string.static String
line(@NonNull CharSequence... patterns)
Generates a regular expression to match the entire line, i.e.static SerializablePredicate<CharSequence>
match(@NonNull CharSequence... pattern)
Creates aSerializablePredicate
to match the given Pattern by calling find on the resulting matcher.static SerializablePredicate<CharSequence>
match(@NonNull Pattern pattern)
Creates aSerializablePredicate
to match the given Pattern by calling find on the resulting matcher.static SerializablePredicate<CharSequence>
matchAll(@NonNull CharSequence... pattern)
Creates aSerializablePredicate
to match the given Pattern by calling matches on the resulting matcher.static SerializablePredicate<CharSequence>
matchAll(@NonNull Pattern pattern)
Creates aSerializablePredicate
to match the given Pattern by calling matches on the resulting matcher.static String
max(int max, @NonNull CharSequence... sequence)
Max string.static String
min(int min, @NonNull CharSequence... sequence)
Min string.static String
namedGroup(@NonNull CharSequence groupName, @NonNull CharSequence... regex)
Defines the given regex as a named match group.static String
negLookahead(@NonNull CharSequence... regex)
Defines a negative lookahead for the given regex.static String
negLookbehind(@NonNull CharSequence... regex)
Defines a negative non-consuming lookahead for the given regex.static String
next(Matcher m)
Next string.static String
nonMatchingGroup(@NonNull CharSequence... regex)
Defines the given regex as a non-matching groupstatic String
notChars(char... chars)
Converts the given array of strings into a negated regex character class.static String
notChars(CharSequence... chars)
Converts the given array of strings into a negated regex character class.static String
oneOrMore(@NonNull CharSequence... sequence)
One or more string.static String
or(@NonNull CharSequence... sequence)
Combines the given regex patterns as alternations.static String
posLookahead(@NonNull CharSequence... regex)
Defines a positive lookahead for the given regex.static String
posLookbehind(@NonNull CharSequence... regex)
Defines a non-consuming positive lookahead for the given regex.static String
q(@NonNull CharSequence pattern)
Q string.static Pattern
r(int flags, @NonNull CharSequence... patterns)
Compiles the given patterns, treating them as a sequence, with the given flags.static Pattern
r(@NonNull CharSequence... patterns)
Compiles the given patterns, treating them as a sequence.static String
range(int min, int max, @NonNull CharSequence... sequence)
Range string.static String
re(@NonNull CharSequence... sequence)
Combines the given regex patterns into a sequence.static String
zeroOrMore(@NonNull CharSequence... sequence)
Zero or more string.static String
zeroOrOne(@NonNull CharSequence... sequence)
Zero or one string.
-
-
-
Field Detail
-
ANY
public static final String ANY
An unescaped period representing match anything.- See Also:
- Constant Field Values
-
BACKSLASH
public static final String BACKSLASH
Backlash character- See Also:
- Constant Field Values
-
CARRIAGE_RETURN
public static final String CARRIAGE_RETURN
The constant CARRIAGE_RETURN.- See Also:
- Constant Field Values
-
CLOSE_PUNCTUATION
public static final String CLOSE_PUNCTUATION
Unicode close punctuation- See Also:
- Constant Field Values
-
CONNECTOR_PUNCTUATION
public static final String CONNECTOR_PUNCTUATION
Unicode connector punctuation- See Also:
- Constant Field Values
-
CURRENCY_SYMBOL
public static final String CURRENCY_SYMBOL
Unicode currency characters- See Also:
- Constant Field Values
-
DASH_PUNCTUATION
public static final String DASH_PUNCTUATION
Unicode dash punctuation- See Also:
- Constant Field Values
-
DIGIT
public static final String DIGIT
Unicode digits- See Also:
- Constant Field Values
-
ESC_BACKSLASH
public static final String ESC_BACKSLASH
Escaped backslash- See Also:
- Constant Field Values
-
FINAL_PUNCTUATION
public static final String FINAL_PUNCTUATION
Unicode final punctuation- See Also:
- Constant Field Values
-
FORM_FEED
public static final String FORM_FEED
The constant FORM_FEED.- See Also:
- Constant Field Values
-
INITIAL_PUNCTUATION
public static final String INITIAL_PUNCTUATION
Unicode initial punctuation- See Also:
- Constant Field Values
-
LETTER
public static final String LETTER
Unicode letter- See Also:
- Constant Field Values
-
LINE_FEED
public static final String LINE_FEED
The constant LINE_FEED.- See Also:
- Constant Field Values
-
LOWERCASE_LETTER
public static final String LOWERCASE_LETTER
Unicode lowercase letter- See Also:
- Constant Field Values
-
MARK
public static final String MARK
Unicode mark characters.- See Also:
- Constant Field Values
-
MATH_SYMBOL
public static final String MATH_SYMBOL
Unicode math symbols- See Also:
- Constant Field Values
-
MODIFIER_SYMBOL
public static final String MODIFIER_SYMBOL
Unicode modifier symbols- See Also:
- Constant Field Values
-
NUMBER
public static final String NUMBER
Unicode numbers- See Also:
- Constant Field Values
-
OPEN_PUNCTUATION
public static final String OPEN_PUNCTUATION
Unicode open punctuation- See Also:
- Constant Field Values
-
OTHER_SYMBOL
public static final String OTHER_SYMBOL
Unicode other symbols- See Also:
- Constant Field Values
-
PUNCTUATION
public static final String PUNCTUATION
Unicode punctuation- See Also:
- Constant Field Values
-
QUOTE
public static final String QUOTE
The quote character.- See Also:
- Constant Field Values
-
SYMBOL
public static final String SYMBOL
Unicode symbol characters- See Also:
- Constant Field Values
-
TAB
public static final String TAB
The constant TAB.- See Also:
- Constant Field Values
-
UNICODE_WHITESPACE
public static final String UNICODE_WHITESPACE
The constant UNICODE_WHITESPACE.- See Also:
- Constant Field Values
-
NON_WHITESPACE
public static final String NON_WHITESPACE
The constant NON_WHITESPACE.
-
UPPERCASE_LETTER
public static final String UPPERCASE_LETTER
Unicode uppercase letter- See Also:
- Constant Field Values
-
WHITESPACE
public static final String WHITESPACE
matches unicode whitespace.
-
MULTIPLE_WHITESPACE
public static final String MULTIPLE_WHITESPACE
The constant MULTIPLE_WHITESPACE.
-
WORD_BOUNDARY
public static final String WORD_BOUNDARY
Word boundary- See Also:
- Constant Field Values
-
ZERO_OR_MORE_WHITESPACE
public static final String ZERO_OR_MORE_WHITESPACE
The constant ZERO_OR_MORE_WHITESPACE.
-
-
Method Detail
-
any
public static String any()
Any string.- Returns:
- the string
-
chars
public static String chars(boolean negated, @NonNull @NonNull CharSequence... chars)
Converts the given array of strings into a regex character class.- Parameters:
negated
- True if the class should be negated.chars
- the components of the character class- Returns:
- the character class
-
chars
public static String chars(boolean negated, @NonNull @lombok.NonNull char... chars)
Converts the given array of characters into a regex character class.- Parameters:
negated
- True if the class should be negated.chars
- the components of the character class- Returns:
- the character class
-
chars
public static String chars(String... chars)
Converts the given array of strings into a regex character class.- Parameters:
chars
- the components of the character class- Returns:
- the character class
-
chars
public static String chars(char... chars)
Converts the given array of chars into a regex character class.- Parameters:
chars
- the components of the character class- Returns:
- the character class
-
e
public static String e(char character)
E string.- Parameters:
character
- the character- Returns:
- the string
-
greedyOneOrMore
public static String greedyOneOrMore(@NonNull @NonNull CharSequence... sequence)
Greedy one or more string.- Parameters:
sequence
- the sequence- Returns:
- the string
-
greedyZeroOrMore
public static String greedyZeroOrMore(@NonNull @NonNull CharSequence... sequence)
Greedy zero or more string.- Parameters:
sequence
- the sequence- Returns:
- the string
-
group
public static String group(@NonNull @NonNull CharSequence... sequence)
Group string.- Parameters:
sequence
- the sequence- Returns:
- the string
-
line
public static String line(@NonNull @NonNull CharSequence... patterns)
Generates a regular expression to match the entire line, i.e.^pattern$
- Parameters:
patterns
- The patterns making up the line- Returns:
- The regluar expresion
-
match
public static SerializablePredicate<CharSequence> match(@NonNull @NonNull Pattern pattern)
Creates aSerializablePredicate
to match the given Pattern by calling find on the resulting matcher.- Parameters:
pattern
- the pattern to match- Returns:
- the
SerializablePredicate
-
match
public static SerializablePredicate<CharSequence> match(@NonNull @NonNull CharSequence... pattern)
Creates aSerializablePredicate
to match the given Pattern by calling find on the resulting matcher.- Parameters:
pattern
- the pattern to match- Returns:
- the
SerializablePredicate
-
matchAll
public static SerializablePredicate<CharSequence> matchAll(@NonNull @NonNull Pattern pattern)
Creates aSerializablePredicate
to match the given Pattern by calling matches on the resulting matcher.- Parameters:
pattern
- the pattern to match- Returns:
- the
SerializablePredicate
-
matchAll
public static SerializablePredicate<CharSequence> matchAll(@NonNull @NonNull CharSequence... pattern)
Creates aSerializablePredicate
to match the given Pattern by calling matches on the resulting matcher.- Parameters:
pattern
- the pattern to match- Returns:
- the
SerializablePredicate
-
max
public static String max(int max, @NonNull @NonNull CharSequence... sequence)
Max string.- Parameters:
max
- the maxsequence
- the sequence- Returns:
- the string
-
min
public static String min(int min, @NonNull @NonNull CharSequence... sequence)
Min string.- Parameters:
min
- the minsequence
- the sequence- Returns:
- the string
-
namedGroup
public static String namedGroup(@NonNull @NonNull CharSequence groupName, @NonNull @NonNull CharSequence... regex)
Defines the given regex as a named match group.- Parameters:
groupName
- the group nameregex
- the regex- Returns:
- the named match group
-
negLookahead
public static String negLookahead(@NonNull @NonNull CharSequence... regex)
Defines a negative lookahead for the given regex.- Parameters:
regex
- the regex- Returns:
- the regex
-
negLookbehind
public static String negLookbehind(@NonNull @NonNull CharSequence... regex)
Defines a negative non-consuming lookahead for the given regex.- Parameters:
regex
- the regex- Returns:
- the regex
-
nonMatchingGroup
public static String nonMatchingGroup(@NonNull @NonNull CharSequence... regex)
Defines the given regex as a non-matching group- Parameters:
regex
- the regex- Returns:
- the non-matching group
-
notChars
public static String notChars(CharSequence... chars)
Converts the given array of strings into a negated regex character class.- Parameters:
chars
- the components of the character class- Returns:
- the negated character class
-
notChars
public static String notChars(char... chars)
Converts the given array of strings into a negated regex character class.- Parameters:
chars
- the components of the character class- Returns:
- the negated character class
-
oneOrMore
public static String oneOrMore(@NonNull @NonNull CharSequence... sequence)
One or more string.- Parameters:
sequence
- the sequence- Returns:
- the string
-
or
public static String or(@NonNull @NonNull CharSequence... sequence)
Combines the given regex patterns as alternations. Should be wrapped as a group.- Parameters:
sequence
- the regex- Returns:
- the alternation
-
posLookahead
public static String posLookahead(@NonNull @NonNull CharSequence... regex)
Defines a positive lookahead for the given regex.- Parameters:
regex
- the regex- Returns:
- the regex
-
posLookbehind
public static String posLookbehind(@NonNull @NonNull CharSequence... regex)
Defines a non-consuming positive lookahead for the given regex.- Parameters:
regex
- the regex- Returns:
- the regex
-
q
public static String q(@NonNull @NonNull CharSequence pattern)
Q string.- Parameters:
pattern
- the pattern- Returns:
- the string
-
r
public static Pattern r(int flags, @NonNull @NonNull CharSequence... patterns)
Compiles the given patterns, treating them as a sequence, with the given flags.- Parameters:
flags
- the flagspatterns
- the patterns- Returns:
- the pattern
-
r
public static Pattern r(@NonNull @NonNull CharSequence... patterns)
Compiles the given patterns, treating them as a sequence.- Parameters:
patterns
- the patterns- Returns:
- the pattern
-
range
public static String range(int min, int max, @NonNull @NonNull CharSequence... sequence)
Range string.- Parameters:
min
- the minmax
- the maxsequence
- the sequence- Returns:
- the string
-
re
public static String re(@NonNull @NonNull CharSequence... sequence)
Combines the given regex patterns into a sequence.- Parameters:
sequence
- the regex- Returns:
- the string
-
zeroOrMore
public static String zeroOrMore(@NonNull @NonNull CharSequence... sequence)
Zero or more string.- Parameters:
sequence
- the sequence- Returns:
- the string
-
zeroOrOne
public static String zeroOrOne(@NonNull @NonNull CharSequence... sequence)
Zero or one string.- Parameters:
sequence
- the sequence- Returns:
- the string
-
-