JavaScript / ECMAScript

JWT Token in JS

Match JSON Web Tokens (JWTs) — three base64url-encoded segments separated by dots.

Try it in the JS tester →

Pattern

regexJS
eyJ[A-Za-z0-9_\-]+\.eyJ[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+   (flags: g)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("eyJ[A-Za-z0-9_\\-]+\\.eyJ[A-Za-z0-9_\\-]+\\.[A-Za-z0-9_\\-]+", "g");
const input = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.abc123-_";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

Both header and payload segments start with eyJ (base64 of '{"'), followed by base64url chars, joined by dots and followed by the signature segment.

Examples

Input

eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.abc123-_

Matches

  • eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.abc123-_

Input

Bearer token-here

No match

Same pattern, other engines

← Back to JWT Token overview (all engines)