Can you remove leading-and-lagging characters-and-substrings from a string without using RegEx-and/or-Custom-Code?
For example, I want to remove leading https:// and lagging / (backslashes).
I can definitely solve this with custom code and/or RegEx. But we don't want to go ahead with these answers after discussion. Many people are uncertain about this change and do not want to spend time learning RegEx to verify. We just want to make it easy and simple to switch-out and verify is working after refactoring. Is there there a package solution or built-in that already handles find-replace first-and-last?
@Value("${elsewhere.host.url:https://url.or.uri.full.or.partial}")
String urlOrUri;
// ...
String scheme = "https://"
// Example 1:
if (urlOrUri.startsWith(scheme))
urlOrUri.replaceFirst(scheme,"");
if (urlOrUri.startsWith("/"))
urlOrUri.replaceFirst("/","");
if (urlOrUri.endsWith("/"))
urlOrUri.replaceLast("/","");
// Example 2:
urlOrUri.replaceFirst("^https://+", "");
urlOrUri.replaceFirst("^/+", "");
urlOrUri.replaceFirst("/+$", "");
/won't work unless there is only that/in the url...