Package org.vaadin.miki.util
Class RegexTools
java.lang.Object
org.vaadin.miki.util.RegexTools
Tools related to regular expressions.
- Since:
- 2023-05-05
- Author:
- miki
-
Field Summary
FieldsModifier and TypeFieldDescriptionCharacters that need to be escaped in a regular expression. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcharacterSelector(char main, char... alternatives) Builds a regular expression that is a selector for a given character(s).static StringcharacterSelector(char mainCharacter, Collection<Character> alternatives) Builds a regular expression that is a selector for a given character(s).static StringBuildercharacterSelector(StringBuilder builder, char mainCharacter, Collection<Character> alternatives) Appends to a given builder a regular expression that is a selector for a given character(s).static Stringescaped(char character) Escapes the character if it needs to in a regular expression that is part of a character selector.static Stringescaped(char character, boolean insideCharSelector) Escapes the character if it needs to in a regular expression.
-
Field Details
-
CHARACTERS_TO_ESCAPE_OUTSIDE_CHAR_SELECTOR
Characters that need to be escaped in a regular expression. -
CHARACTERS_TO_ESCAPE_ONLY_IN_CHAR_SELECTOR
-
-
Method Details
-
escaped
Escapes the character if it needs to in a regular expression that is part of a character selector. This is the same as callingescaped(character, true).- Parameters:
character- Character to escape.- Returns:
- Escaped character (if needed), otherwise the passed character.
- See Also:
-
escaped
Escapes the character if it needs to in a regular expression.- Parameters:
character- Character to escape.insideCharSelector- Iftrue,CHARACTERS_TO_ESCAPE_ONLY_IN_CHAR_SELECTORwill be used to check if a character needs to be escaped; otherwiseCHARACTERS_TO_ESCAPE_OUTSIDE_CHAR_SELECTORwill be used.- Returns:
- Escaped character (if needed), otherwise the passed character.
-
characterSelector
public static StringBuilder characterSelector(StringBuilder builder, char mainCharacter, Collection<Character> alternatives) Appends to a given builder a regular expression that is a selector for a given character(s).- Parameters:
builder- Builder to add the regular expression to.mainCharacter- The character to select.alternatives- Eventual alternatives.- Returns:
- The passed builder.
-
characterSelector
Builds a regular expression that is a selector for a given character(s).- Parameters:
mainCharacter- The character to select.alternatives- Eventual alternatives.- Returns:
- A regular expression that matches the character or its alternatives.
-
characterSelector
Builds a regular expression that is a selector for a given character(s).- Parameters:
main- The character to select.alternatives- Eventual alternatives.- Returns:
- A regular expression that matches the character or its alternatives.
-