Pattern library / Strings & Text
Regex to Match JWT (JSON Web Token) Structure
Validates the header.payload.signature shape using Base64URL characters. Does not verify the signature — use a JWT library for that.
How the pattern works
[A-Za-z0-9_-]+— Base64URL alphabet (no + / or padding).- Three segments separated by dots: header, payload, signature.
- Always verify signatures with a real JWT library; regex only checks shape.
Test it: match & no-match examples
Every row is loaded straight into the tester — click Try to see the match live:
| Input | Result | Why | |
|---|---|---|---|
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U | Match | valid JWT shape | Try → |
a.b | No match | only two parts | Try → |
a.b.c.d | No match | four parts | Try → |
header.payload.sig! | No match | invalid char ! | Try → |
Where to use it
JavaScript
const re = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/; re.test(token); // true
Python
import re re.match(r'^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$', token)
Common mistakes
Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
FAQ
Related patterns
For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.