Skip to content

Instantly share code, notes, and snippets.

@du5rte
Created March 15, 2017 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save du5rte/08504a218e3ad7c18a93ecdc26f56b91 to your computer and use it in GitHub Desktop.
Save du5rte/08504a218e3ad7c18a93ecdc26f56b91 to your computer and use it in GitHub Desktop.
Regex JWT
const authorization = "Bearer abcefghijklmnopqrstu.vwxyzABCDEFGHIJKLMNOPQ.RSTUVWXYZ0123456789"
// (?:__) no selection group
// (__)? optional selection group
// (__) selection group
// searchers for digits seperated by three dots xx.xx.xx with an optional "Bearer "
// retrieve only the jwt (without Bearer)
const jwt = authorization.match(/(?:Bearer\s+)?(\w+\.\w+\.\w+)/)[1] // "abcef..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment