java.lang.Object
net.foxgenesis.util.StringUtils
Utility class for Strings
- Author:
- Ashley
-
Field Summary
FieldsModifier and TypeFieldDescriptionPredicate that tests if a URL is found in a given input string.Predicate that tests if the given input string is a URL.static final PatternCompiled regex checking for URL character sequences.static final PatternCompiled regex checking for URL character sequences. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionFind all occurrences of aURLin the given string.Find all occurrences of aURLin the given string.static Stream<MatchResult>findURLWithGroups(String str) Find all URLs within a String and split its components into groups.static StringLimit the length of a string if it exceeds the provided length.
-
Field Details
-
PATTERN_URL
Compiled regex checking for URL character sequences. This pattern is case insensitive.\b((http|https|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]) -
PATTERN_URL_WITH_GROUPING
Compiled regex checking for URL character sequences. This pattern is case insensitive and contains named groups forprotocol,domainandpath.\b(?<protocol>http|https|ftp|file)://(?<domain>[-a-zA-Z0-9+&@#%?=~_|!:,.;]*[-a-zA-Z0-9+&@#%=~_|])(?<path>\S*) -
CONTAINS_URL
Predicate that tests if a URL is found in a given input string. -
IS_URL
Predicate that tests if the given input string is a URL.
-
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
findURLWithGroups
Find all URLs within a String and split its components into groups.- Parameters:
str- - String to check- Returns:
- A
StreamofMatchResultscontaining URL groups:protocol(1),domain(2) andpath(3)
-
findURLs
Find all occurrences of aURLin the given string. -
findURLs
@Nonnull public static Stream<URL> findURLs(@Nonnull String str, @Nullable Consumer<Exception> errorHandler) Find all occurrences of aURLin the given string. AllMalformedURLExceptionswill be consumed by theerrorHandlerwhile parsing. -
limit
Limit the length of a string if it exceeds the provided length.- Parameters:
str- - string to limitlength- - length limit- Returns:
- Returns a
Stringthat does not exceed the givenlength
-