Skip to main content
Authentication & Security · In-Browser Regular Expression Lab

JWT Regex — Validate Base64URL Encoded Header, Payload & Signature

Validates standard 3-part JSON Web Tokens (Header.Payload.Signature) in Base64URL encoding.

Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c Pass

Expected Invalid Samples (Must Reject)

invalid.jwt Rejected (Pass)
header.payload Rejected (Pass)
a.b.c.d Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
const text = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Checks three dot-separated Base64URL character sequences corresponding to JWT structure. Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
^[A-Za-z0-9_-]+HeaderBase64URL encoded JSON header.
\.Dot separatorSeparator between header and payload.
[A-Za-z0-9_-]+PayloadBase64URL encoded JSON claims.
\.Dot separatorSeparator between payload and signature.
[A-Za-z0-9_-]+$SignatureCryptographic HMAC or RSA signature.

Frequently Asked Questions

Does regex verify signature validity?
No, regex only validates token structure. Cryptographic verification requires secret key parsing.
Browse All 40 Patterns