I've two string token, I'm checking the pattern and send both the token back with ":"
delimiter.
Input :
String oldToken = "Bearer IdmH0VCifziTjHNGfyKfK9YCoEsy6nTDI";
String newToken = "Bearer IdsfdWeRrrfziTjHNGfyKfK9YCoEsy6nTDI";
Output:
IdmH0VCifziTjHNGfyKfK9YCoEsy6nTDI : IdsfdWeRrrfziTjHNGfyKfK9YCoEsy6nTDI
Please find my code below:
public class TestToken {
public static void main(String[] args) {
String oldToken = "Bearer IdmH0VCifziTjHNGfyKfK9YCoEsy6nTDI";
String newToken = "Bearer IdsfdWeRrrfziTjHNGfyKfK9YCoEsy6nTDI";
String result = getToken(oldToken, newToken);
System.out.println("result: " +result);
}
private static String getToken(String oldtoken, String newToken) {
Pattern pattern = Pattern.compile(
"^Bearer (?<token>[a-zA-Z0-9-._~+/]+)=*$",
Pattern.CASE_INSENSITIVE);
Matcher matcher =null;
if (StringUtils.startsWithIgnoreCase(oldtoken, "bearer")) {
matcher = pattern.matcher(oldtoken);
boolean matchResult = matcher.matches();
}
return matcher.group("token");
}
}
How can I combine both these token in this case and return it back. Any help would be really appreciated. Thanks!