How the pattern works
| Part | Meaning |
|---|---|
[A-Za-z0-9_-]+ | The header, base64url-encoded |
\. | A dot |
[A-Za-z0-9_-]+ | The payload |
[A-Za-z0-9_-]*$ | The signature (empty for unsigned tokens) |
Code examples
JavaScript
const re = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/;
re.test(value); // true or falsePython
import re
bool(re.fullmatch(r'[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*', value))PHP
preg_match('/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/', $value) === 1;
Notes and limitations
Matching the shape tells you nothing about whether a token is valid — always verify the signature on the server. Inspect a token with the JWT Decoder.
Regex TesterType a pattern and watch matches highlight live in your test text.
Open the tool Frequently asked questions
What is the regex for JSON Web Token (JWT)?
/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/ — it matches the whole string. See the table above for what each part does.
Which examples match?
Of the examples tested, these match: eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjMifQ.sig_abc-123, eyJhbGciOiJub25lIn0.eyJzdWIiOiIxIn0.. The others don’t.
How do I test this regex?
Click “Open in Regex Tester” — the pattern, flags and sample text load automatically, and matches highlight as you edit.