-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
Regular expression pattern used to remove double-quoted string parts.
The regular expression allows escaped double quotes inside the string.private static final String
Constant for system property 'lang.match.in.quotes'.private static final String
Constant for system property 'lang.surrounded.reverse.brackets'.private static final String
Regular expression pattern used to remove single-quoted string parts.
The regular expression allows escaped single quotes inside the string. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Private constructor to prevent instantiation.
This is a static helper class. -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
baseDifference
(@Nullable String base, @Nullable String compare) Does the base difference calculation for the given strings.static boolean
containsNotEscaped
(@Nullable String str, char target) Checks if the string contains the given target character.
The target character will be ignored if it is escaped with a backslash.
If the string is empty or null, false will be returned.static int
countDifference
(@Nullable String base, @Nullable String compare) Counts the difference between the given strings.static int
countDifferenceAligned
(@Nullable String base, @Nullable String compare) Counts the difference between the given strings, aligned.
The difference will be counted in both directions, and the lowest difference will be returned.static int
countDifferenceBackwards
(@Nullable String base, @Nullable String compare) Counts the difference between the given strings, backwards.static int
countDifferenceBackwardsStripped
(@Nullable String base, @Nullable String compare) Counts the difference between the given strings, backwards, after stripping them.static int
countDifferenceStripped
(@Nullable String base, @Nullable String compare) Counts the difference between the given strings, after stripping them.static String @NotNull []
Extracts all groups from the given string which match the given regex.static String @NotNull []
Extract all groups from the given string which match the given pattern.findSimilar
(@Nullable String base, int allowDifference, String @Nullable ... values) Finds similar strings to the given base string.
A value will be considered similar if the difference is less or equal to the givenallowDifference
.
The similarity will be checked with default counter-functioncountDifference(String, String)
.findSimilar
(@Nullable String base, int allowDifference, @Nullable List<String> values) Finds similar strings to the given base string.
A value will be considered similar if the difference is less or equal to the givenallowDifference
.
The similarity will be checked with default counter-functioncountDifference(String, String)
.findSimilar
(@Nullable String base, int allowDifference, @Nullable ToIntBiFunction<String, String> counter, @Nullable List<String> values) Finds similar strings to the given base string.
A value will be considered similar if the difference is less or equal to the givenallowDifference
.
The similarity will be checked with the given counter-function.static char
getOppositeBracket
(char bracket) Gets the opposite bracket of the givenbracket
.
If the given character is not a bracket,'\0'
will be returned.static @NotNull String
getReadableString
(@Nullable String str, @Nullable Predicate<Character> condition) Converts the given string to a readable string.indexOfAll
(@Nullable String str, char search) Searches for occurrences of the givensearch
character in the given string.
The index of the found occurrences will be returned in a list.
If the given string is empty, an empty list will be returned.indexOfAll
(@Nullable String str, @Nullable String search) Searches for occurrences of the givensearch
string in the given string.
The occurred indexes will be returned in a list.
If the given string or the search string is empty, an empty list will be returned.static boolean
isAfterAllOccurrence
(@Nullable String str, char target, String @Nullable ... follows) Checks if the giventarget
character is followed by any string inside the givenfollows
array.
If thetarget
character is found in the given string, all occurrences will be checked.static boolean
isBeforeAllOccurrence
(@Nullable String str, char target, String @Nullable ... precedes) Checks if the giventarget
character is preceded by any string inside the givenprecedes
array.
If thetarget
character is found, all occurrences will be checked.static boolean
isSurroundedBy
(@Nullable String str, char target, String @Nullable ... surrounded) Checks if the giventarget
character is surrounded by any string inside the givensurrounded
array.
If the target character is found, all occurrences will be checked.static int
levenshteinDistance
(@Nullable String base, @Nullable String compare) Calculates the levenshtein distance between the given strings.static boolean
matchesPattern
(@Nullable Pattern pattern, @Nullable String str) Checks if the given string matches the given pattern.static boolean
matchingBalanced
(@Nullable String str, char open, char close) Checks if the given string is matching balanced.
This means that the open and close characters are in the correct order and have the same number of occurrences.static boolean
matchingBalanced
(@Nullable String str, @Nullable String open, @Nullable String close) Checks if the given string is matching balanced.
This means that the open and close strings are in the correct order and have the same number of occurrences.static @NotNull String
removeQuoted
(@Nullable String str) Removes quoted parts from the given string.static @NotNull String
reverseIncludeBrackets
(@Nullable String str) Reverses the given string including brackets.
If the given string is null or empty, an empty string will be returned.static String @NotNull []
splitNotEscaped
(@Nullable String str, char target) Splits the given string by the given target character.
The target character will be ignored if it is escaped with a backslash.
If the string is empty or null, an empty array will be returned.
-
Field Details
-
SINGLE_QUOTE_PATTERN
Regular expression pattern used to remove single-quoted string parts.
The regular expression allows escaped single quotes inside the string.- See Also:
-
DOUBLE_QUOTE_PATTERN
Regular expression pattern used to remove double-quoted string parts.
The regular expression allows escaped double quotes inside the string.- See Also:
-
LANG_SURROUNDED_REVERSE_BRACKETS
Constant for system property 'lang.surrounded.reverse.brackets'.
This property is used in
isSurroundedBy(String, char, String...)
to determine
if the brackets should be reversed.
The default value is
false
.
- See Also:
-
LANG_MATCH_IN_QUOTES
Constant for system property 'lang.match.in.quotes'.
This property is used in
matchingBalanced(String, String, String)
to determine
if occurrences of theopen
andclose
strings should be match inside quotes.
The default value is
false
.
- See Also:
-
-
Constructor Details
-
StringUtils
private StringUtils()Private constructor to prevent instantiation.
This is a static helper class.
-
-
Method Details
-
getOppositeBracket
public static char getOppositeBracket(char bracket) Gets the opposite bracket of the givenbracket
.
If the given character is not a bracket,'\0'
will be returned.
Examples:
getOppositeBracket('(') -> ')' getOppositeBracket(']') -> '[' getOppositeBracket('{') -> '}' getOppositeBracket('<') -> '>' getOppositeBracket('a') -> '\0'
- Parameters:
bracket
- The bracket to get the opposite of- Returns:
- The opposite bracket of the given character or
'\0'
if the given character is not a bracket
-
reverseIncludeBrackets
Reverses the given string including brackets.
If the given string is null or empty, an empty string will be returned.
Examples:
reverseIncludeBrackets(null) -> "" reverseIncludeBrackets("") -> "" reverseIncludeBrackets("abc") -> "cba" reverseIncludeBrackets("a(bc)") -> "(cb)a" reverseIncludeBrackets("a<bc>") -> "<cb>a"
- Parameters:
str
- The string to reverse- Returns:
- The reversed string including brackets
-
indexOfAll
@NotNull public static @NotNull List<Integer> indexOfAll(@Nullable @Nullable String str, char search) Searches for occurrences of the givensearch
character in the given string.
The index of the found occurrences will be returned in a list.
If the given string is empty, an empty list will be returned.
Examples:
indexOfAll(null, *) -> [] indexOfAll("", *) -> [] indexOfAll("abc", 'a') -> [0] indexOfAll("aba", 'a') -> [0, 2] indexOfAll(" ", ' ') -> [0, 1, 2]
- Parameters:
str
- The string to search insearch
- The character to search for- Returns:
- A list with the indexes of all occurrences in the given character
-
indexOfAll
@NotNull public static @NotNull List<Integer> indexOfAll(@Nullable @Nullable String str, @Nullable @Nullable String search) Searches for occurrences of the givensearch
string in the given string.
The occurred indexes will be returned in a list.
If the given string or the search string is empty, an empty list will be returned.
Examples:
indexOfAll(null, *) -> [] indexOfAll("", *) -> [] indexOfAll("abed", "a") -> [0] indexOfAll("abac", "ab") -> [0] indexOfAll("abac ba", "ba") -> [1, 4]
- Parameters:
str
- The string to search insearch
- The string to search for- Returns:
- A list with the indexes of all occurrences in the given string
-
baseDifference
private static int baseDifference(@Nullable @Nullable String base, @Nullable @Nullable String compare) Does the base difference calculation for the given strings.
If both strings are equal, 0 will be returned.
If one of the strings is empty or null, the length of the other string will be returned.
In any other case, -1 will be returned.
- Parameters:
base
- The base stringcompare
- The string to compare- Returns:
- The difference between the given strings
- See Also:
-
countDifference
public static int countDifference(@Nullable @Nullable String base, @Nullable @Nullable String compare) Counts the difference between the given strings.
If both strings are equal, empty or null, 0 will be returned.
If one of the strings is empty or null, the length of the other string will be returned.
Examples:
countDifference(null, null) -> 0 countDifference("", "") -> 0 countDifference("abc", "abc") -> 0 countDifference("xyz", "abc") -> 3 countDifference("abcde", "abc ") -> 2 countDifference("abcde", " cde") -> 2 countDifference("abcde", "cde") -> 5
- Parameters:
base
- The base stringcompare
- The string to compare- Returns:
- The difference between the given strings
- See Also:
-
countDifferenceStripped
public static int countDifferenceStripped(@Nullable @Nullable String base, @Nullable @Nullable String compare) Counts the difference between the given strings, after stripping them.
If both strings are equal, empty or null, 0 will be returned.
If one of the strings is empty or null, the length of the other string will be returned.
Examples:
countDifferenceStripped(null, null) -> 0 countDifferenceStripped("", "") -> 0 countDifferenceStripped("abc", "abc") -> 0 countDifferenceStripped("xyz", "abc") -> 3 countDifferenceStripped("abcde", " abc") -> 2 countDifferenceStripped("abcde", " cde") -> 5 countDifferenceStripped("abcde", "cde") -> 5
- Parameters:
base
- The base stringcompare
- The string to compare- Returns:
- The difference between the given strings
- See Also:
-
countDifferenceBackwards
public static int countDifferenceBackwards(@Nullable @Nullable String base, @Nullable @Nullable String compare) Counts the difference between the given strings, backwards.
If both strings are equal, empty or null, 0 will be returned.
If one of the strings is empty or null, the length of the other string will be returned.
Examples:
countDifferenceBackwards(null, null) -> 0 countDifferenceBackwards("", "") -> 0 countDifferenceBackwards("abc", "abc") -> 0 countDifferenceBackwards("xyz", "abc") -> 3 countDifferenceBackwards("abcde", " abc") -> 5 countDifferenceBackwards("abcde", " cde") -> 2 countDifferenceBackwards("abcde", "cde") -> 2
- Parameters:
base
- The base stringcompare
- The string to compare- Returns:
- The difference between the given strings
- See Also:
-
countDifferenceBackwardsStripped
public static int countDifferenceBackwardsStripped(@Nullable @Nullable String base, @Nullable @Nullable String compare) Counts the difference between the given strings, backwards, after stripping them.
If both strings are equal, empty or null, 0 will be returned.
If one of the strings is empty or null, the length of the other string will be returned.
Examples:
countDifferenceBackwardsStripped(null, null) -> 0 countDifferenceBackwardsStripped("", "") -> 0 countDifferenceBackwardsStripped("abc", "abc") -> 0 countDifferenceBackwardsStripped("xyz", "abc") -> 3 countDifferenceBackwardsStripped("abcde", "abc ") -> 5 countDifferenceBackwardsStripped("abcde", "cde ") -> 2 countDifferenceBackwardsStripped("abcde", "cde") -> 2
- Parameters:
base
- The base stringcompare
- The string to compare- Returns:
- The difference between the given strings
- See Also:
-
countDifferenceAligned
public static int countDifferenceAligned(@Nullable @Nullable String base, @Nullable @Nullable String compare) Counts the difference between the given strings, aligned.
The difference will be counted in both directions, and the lowest difference will be returned.
If both strings are equal, empty or null, 0 will be returned.
If one of the strings is empty or null, the length of the other string will be returned.
Examples:
countDifferenceAligned(null, null) -> 0 countDifferenceAligned("", "") -> 0 countDifferenceAligned("abc", "abc") -> 0 countDifferenceAligned("xyz", "abc") -> 3 countDifferenceAligned("abcde", "abc ") -> 2 countDifferenceAligned("abcde", " cde") -> 2 countDifferenceAligned("abcde", "cde") -> 2
- Parameters:
base
- The base stringcompare
- The string to compare- Returns:
- The difference between the given strings
- See Also:
-
levenshteinDistance
public static int levenshteinDistance(@Nullable @Nullable String base, @Nullable @Nullable String compare) Calculates the levenshtein distance between the given strings.
If both strings are equal, empty or null, 0 will be returned.
If one of the strings is empty or null, the length of the other string will be returned.
Examples:
levenshteinDistance(null, *) -> 0 levenshteinDistance(*, null) -> 0 levenshteinDistance("", *) -> 0 levenshteinDistance(*, "") -> 0 levenshteinDistance("abc", "") -> 3 levenshteinDistance("", "abc") -> 3 levenshteinDistance("abc", "abc") -> 0 levenshteinDistance("abc", "def") -> 3 levenshteinDistance("test", "text") -> 1 levenshteinDistance("abed", "tset") -> 3
- Parameters:
base
- The base stringcompare
- The string to compare- Returns:
- The levenshtein distance between the given strings
-
findSimilar
@NotNull public static @NotNull List<String> findSimilar(@Nullable @Nullable String base, int allowDifference, String @Nullable ... values) Finds similar strings to the given base string.
A value will be considered similar if the difference is less or equal to the givenallowDifference
.
The similarity will be checked with default counter-functioncountDifference(String, String)
.
In the following cases, an empty list will be returned:
- The base string is empty
- The allowed difference is less than 0
- The given array of values is null or empty
Examples:
findSimilar(null, *, *) -> [] findSimilar("", * *) -> [] findSimilar(*, -1, *) -> [] findSimilar(*, *, null) -> [] findSimilar("abc", 1, ["abc", "def", "ghi"]) -> ["abc"] findSimilar("ab*", 1, ["ab0", "ab1"]) -> ["ab0", "ab1"] findSimilar("abc", 2 ["bcd", "cde", "def", "efg"]) -> []
- Parameters:
base
- The base stringallowDifference
- The allowed difference between the base string and the valuesvalues
- The array of values to check- Returns:
- A list with all similar strings to the base string
- See Also:
-
findSimilar
@NotNull public static @NotNull List<String> findSimilar(@Nullable @Nullable String base, int allowDifference, @Nullable @Nullable List<String> values) Finds similar strings to the given base string.
A value will be considered similar if the difference is less or equal to the givenallowDifference
.
The similarity will be checked with default counter-functioncountDifference(String, String)
.
In the following cases, an empty list will be returned:
- The base string is empty
- The allowed difference is less than 0
- The given list of values is null or empty
Examples:
findSimilar(null, *, *) -> [] findSimilar("", * *) -> [] findSimilar(*, -1, *) -> [] findSimilar(*, *, null) -> [] findSimilar("abc", 1, ["abc", "def", "ghi"]) -> ["abc"] findSimilar("ab*", 1, ["ab0", "ab1"]) -> ["ab0", "ab1"] findSimilar("abc", 2 ["bcd", "cde", "def", "efg"]) -> []
- Parameters:
base
- The base stringallowDifference
- The allowed difference between the base string and the valuesvalues
- The list of values to check- Returns:
- A list with all similar strings to the base string
- See Also:
-
findSimilar
@NotNull public static @NotNull List<String> findSimilar(@Nullable @Nullable String base, int allowDifference, @Nullable @Nullable ToIntBiFunction<String, String> counter, @Nullable @Nullable List<String> values) Finds similar strings to the given base string.
A value will be considered similar if the difference is less or equal to the givenallowDifference
.
The similarity will be checked with the given counter-function.
In the following cases, an empty list will be returned:
- The base string is empty
- The allowed difference is less than 0
- The given list of values is null or empty
Examples:
findSimilar(null, *, *, *) -> [] findSimilar("", *, *, *) -> [] findSimilar(*, -1, *, *) -> [] findSimilar(*, *, null, *) -> [] findSimilar(*, *, *, null) -> [] findSimilar(*, *, *, []) -> []
- Parameters:
base
- The base stringallowDifference
- The allowed difference between the base string and the valuescounter
- The counter-function to check the differencevalues
- The list of values to check- Returns:
- A list with all similar strings to the base string
-
isAfterAllOccurrence
public static boolean isAfterAllOccurrence(@Nullable @Nullable String str, char target, String @Nullable ... follows) Checks if the giventarget
character is followed by any string inside the givenfollows
array.
If thetarget
character is found in the given string, all occurrences will be checked.
If all occurrences of the
target
character are followed by any string inside thefollows
array,
true will be returned.
If the string is empty or the character is not found, false will be returned.
Examples:
isAfterAllOccurrence(null, *, *) -> false isAfterAllOccurrence("", *, *) -> false isAfterAllOccurrence(*, *, null) -> false isAfterAllOccurrence("abcde", 'a', []) -> true isAfterAllOccurrence("abcde", 'x', []) -> false // No occurrence isAfterAllOccurrence("abcde", 'a', ["b"]) -> true // First occurrence matches isAfterAllOccurrence("abcab", 'a', ["b"]) -> true // Both occurrences match isAfterAllOccurrence("abcae", 'a', ["b"]) -> false // Second occurrence does not match isAfterAllOccurrence("abcae", 'a', ["b", "e"]) -> true // Both occurrences match
- Parameters:
str
- The string to checktarget
- The character to check if it is followed by any stringfollows
- The strings to check if any of themfollows
the target character- Returns:
- True if the string contains the target character, and it is followed by any string inside the
follows
array, false otherwise
-
isBeforeAllOccurrence
public static boolean isBeforeAllOccurrence(@Nullable @Nullable String str, char target, String @Nullable ... precedes) Checks if the giventarget
character is preceded by any string inside the givenprecedes
array.
If thetarget
character is found, all occurrences will be checked.
If all occurrences of the
target
character are preceded by any string inside theprecedes
array,
true will be returned.
If the string is empty or the character is not found, false will be returned.
Examples:
isBeforeAllOccurrence(null, *, *) -> false isBeforeAllOccurrence("", *, *) -> false isBeforeAllOccurrence(*, *, null) -> false isBeforeAllOccurrence("abcde", 'd', []) -> true isBeforeAllOccurrence("abcde", 'x', []) -> false // No occurrence isBeforeAllOccurrence("abcde", 'e', ["d"]) -> true // First occurrence matches isBeforeAllOccurrence("aecae", 'e', ["a"]) -> true // Both occurrences match isBeforeAllOccurrence("aecde", 'e', ["a"]) -> false // Second occurrence does not match isBeforeAllOccurrence("aecde", 'e', ["a", "d"]) -> true // Both occurrences match
- Parameters:
str
- The string to checktarget
- The character to check if it is preceded by any stringprecedes
- The strings to check if any of themprecedes
the target character- Returns:
- True if the string contains the target character, and it is preceded by any string inside the
precedes
array, false otherwise
-
isSurroundedBy
public static boolean isSurroundedBy(@Nullable @Nullable String str, char target, String @Nullable ... surrounded) Checks if the giventarget
character is surrounded by any string inside the givensurrounded
array.
If the target character is found, all occurrences will be checked.
If the
target
character is found, and it is surrounded by any string inside thesurrounded
array,
true will be returned.
If the string is empty or the character is not found, false will be returned.
The strings inside the
surrounded
array will be checked in the order they are given.
Each string will be reversed to check if it's before thetarget
character.
If the system property 'lang.surrounded.reverse.brackets' is set to true,
the strings inside thesurrounded
array will be reversed including brackets.
Examples:
isSurroundedBy(null, *, *) -> false isSurroundedBy("", *, *) -> false isSurroundedBy(*, *, null) -> false isSurroundedBy("a.*.b", '*', []) -> true isSurroundedBy("a.*.b", 'x', []) -> false // No occurrence isSurroundedBy("a.*.b", '*', ["."]) -> true // First occurrence matches isSurroundedBy("a.*.b.*.c", '*', ["."]) -> true // Both occurrences match isSurroundedBy("a.*.b.?*?.c", '*', ["."]) -> false // Second occurrence does not match isSurroundedBy("a.*.b.?*?.c", '*', [".", "?"]) -> true // Both occurrences match isSurroundedBy("a.*.b.?*?.c", '*', [".", "?."]) -> true // Both occurrences match // With system property 'lang.surrounded.reverse.brackets' set to true isSurroundedBy("a.[*].b", '*', ["]."]) -> true isSurroundedBy("a.[*[.b", '*', ["[."]) -> false
- Parameters:
str
- The string to checktarget
- The character to check if it is surrounded by any stringsurrounded
- The strings to check if any of them surrounds the target character- Returns:
- True if the string contains the target character, and it is surrounded by any string inside the
surrounded
array, false otherwise - See Also:
-
removeQuoted
Removes quoted parts from the given string.
Double quotes will be removed before single quotes.
If a quote is escaped with a backslash, it will be ignored.
Examples:
removeQuoted(null) -> "" removeQuoted("") -> "" removeQuoted("abc") -> "abc" removeQuoted("a\"b\"c") -> "ac" removeQuoted("a'b'c") -> "ac" removeQuoted("a\"b\\\"c\"d") -> "ad" removeQuoted("a'b\\'c'd") -> "ad" removeQuoted("a\"b'c\"d'e") -> "ad'e"
- Parameters:
str
- The string to remove the quoted parts from- Returns:
- The string without the quoted parts
-
matchingBalanced
Checks if the given string is matching balanced.
This means that the open and close characters are in the correct order and have the same number of occurrences.
If the system property 'lang.match.in.quotes' is set to false,
double and single quotes will be removed from the string before checking.
Examples:
matchingBalanced(null, *, *) -> false matchingBalanced("", *, *) -> true matchingBalanced(" ", *, *) -> true matchingBalanced("(", '(', '(') -> true matchingBalanced("(", '(', ')') -> false matchingBalanced("(())", '(', ')') -> true matchingBalanced("(()", '(', ')') -> false // With system property 'lang.match.in.quotes' set to true matchingBalanced("(\"(\")", '(', ')') -> false matchingBalanced("('(')", '(', ')') -> false matchingBalanced("((\")\")", '(', ')') -> true matchingBalanced("((')')", '(', ')') -> true
- Parameters:
str
- The string to checkopen
- The open characterclose
- The close character- Returns:
- True if the string is matching balanced, false otherwise
- See Also:
-
matchingBalanced
public static boolean matchingBalanced(@Nullable @Nullable String str, @Nullable @Nullable String open, @Nullable @Nullable String close) Checks if the given string is matching balanced.
This means that the open and close strings are in the correct order and have the same number of occurrences.
If the system property 'lang.match.in.quotes' is set to false,
double and single quotes will be removed from the string before checking.
Examples:
matchingBalanced(null, *, *) -> true matchingBalanced(*, null, null) -> true matchingBalanced(*, null, *) -> false matchingBalanced(*, *, null) -> false matchingBalanced("", *, *) -> true matchingBalanced(" ", *, *) -> true matchingBalanced("(", "(", "(") -> true matchingBalanced("(", "(", ")") -> false matchingBalanced("(())", "(", ")") -> true matchingBalanced("(()", "(", ")") -> false // With system property 'lang.match.in.quotes' set to true matchingBalanced("(\"(\")", "(", ")") -> false matchingBalanced("('(')", "(", ")") -> false matchingBalanced("((\")\")", "(", ")") -> true matchingBalanced("((')')", "(", ")") -> true
- Parameters:
str
- The string to checkopen
- The open stringclose
- The close string- Returns:
- True if the string is matching balanced, false otherwise
- See Also:
-
matchesPattern
public static boolean matchesPattern(@Nullable @Nullable Pattern pattern, @Nullable @Nullable String str) Checks if the given string matches the given pattern.
Examples:
matchesPattern(null, null) -> true matchesPattern(null, *) -> false matchesPattern(*, null) -> false matchesPattern(Pattern.compile("a"), "a") -> true matchesPattern(Pattern.compile("a"), "b") -> false
- Parameters:
pattern
- The pattern to matchstr
- The string to check- Returns:
- True if the string matches the pattern, false otherwise
-
containsNotEscaped
Checks if the string contains the given target character.
The target character will be ignored if it is escaped with a backslash.
If the string is empty or null, false will be returned.
Examples:
containsNotEscaped(null, *) -> false containsNotEscaped("", *) -> false containsNotEscaped("abc", 'a') -> true containsNotEscaped("aba", 'c') -> false containsNotEscaped("\\abc", 'a') -> false containsNotEscaped("\\aba", 'a') -> true
- Parameters:
str
- The string to checktarget
- The target character to check- Returns:
- True if the string contains the target character not escaped, false otherwise
-
splitNotEscaped
Splits the given string by the given target character.
The target character will be ignored if it is escaped with a backslash.
If the string is empty or null, an empty array will be returned.
Examples:
splitNotEscaped(null, *) -> [] splitNotEscaped("", *) -> [] splitNotEscaped("abc", 'b') -> ["a", "c"] splitNotEscaped("a\\bc", 'b') -> ["abc"] splitNotEscaped("a\\bc", 'c') -> ["a\\b"] splitNotEscaped("a\\:b:c:d\\:e", ':') -> ["a\\:b", "c", "d\\:e"]
- Parameters:
str
- The string to splittarget
- The target character to split by- Returns:
- The parts of the string split by the target character
-
extract
public static String @NotNull [] extract(@Nullable @Nullable String str, @Language("RegExp") @Nullable @Nullable String regex) Extracts all groups from the given string which match the given regex.
If the string is null or empty, an empty array will be returned.
If the regex is null, empty or does not match, an empty array will be returned.
Examples:
extract(null, null) -> [] extract(null, *) -> [] extract(*, null) -> [] extract("", *) -> [] extract(*, "") -> [] extract("abc", "a") -> ["a"] extract("abc", "abc") -> ["abc"] extract("abc.[def].ghi", "\\[.*?]") -> ["[def]"]
- Parameters:
str
- The string to extract the groups fromregex
- The regex to match- Returns:
- The extracted groups
-
extract
public static String @NotNull [] extract(@Nullable @Nullable String str, @Nullable @Nullable Pattern pattern) Extract all groups from the given string which match the given pattern.
If the string is null or empty, an empty array will be returned.
If the pattern is null or does not match, an empty array will be returned.
Examples:
extract(null, null) -> [] extract(null, *) -> [] extract(*, null) -> [] extract("abc", Pattern.compile("a")) -> ["a"] extract("abc", Pattern.compile("abc")) -> ["abc"] extract("abc.[def].ghi", Pattern.compile("\\[.*?]")) -> ["[def]"]
- Parameters:
str
- The string to extract the groups frompattern
- The pattern to match- Returns:
- The extracted groups
-
getReadableString
@NotNull public static @NotNull String getReadableString(@Nullable @Nullable String str, @Nullable @Nullable Predicate<Character> condition) Converts the given string to a readable string.
The string will be split by the given condition.
The first character of each part will be capitalized, the rest will be lowercased.
The parts will be joined by a space.
If the string is null or empty, an empty string will be returned.
If the condition is null, the string will be returned as is.
Examples:
getReadableString(null, *) -> "" getReadableString("", *) -> "" getReadableString("abc", null) -> "abc" getReadableString("abc", Character::isUpperCase) -> "abc" getReadableString("abc", Character::isLowerCase) -> "A B C" getReadableString("abcDEFghi", Character::isUpperCase) -> "abc D E Fghi"
- Parameters:
str
- The string to convertcondition
- The condition to split the string by- Returns:
- The readable string
-