Skip to content

Instantly share code, notes, and snippets.

@vicly
Created August 8, 2018 01:25
Show Gist options
  • Save vicly/522d939aebb541ac0ea2059844e118ca to your computer and use it in GitHub Desktop.
Save vicly/522d939aebb541ac0ea2059844e118ca to your computer and use it in GitHub Desktop.
[JWT Regex] #Java #Regex
private static final Charset UTF_8 = Charset.forName("UTF-8");
private static final Pattern JWT_PATTERN = Pattern.compile("^([a-zA-Z0-9\\-_]+=*)\\.([a-zA-Z0-9\\-_]+=*)\\.([a-zA-Z0-9\\-_]+=*)$");
Matcher matcher = JWT_PATTERN.matcher(jwt);
if (matcher.matches())
{
String header = matcher.group(1);
String body = matcher.group(2);
String signature = matcher.group(3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment