Python (re)

JWT Token in PY

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

Try it in the PY tester →

Pattern

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

Python (re) code

pyPython
import re

pattern = re.compile(r"eyJ[A-Za-z0-9_\-]+\.eyJ[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+")
input_text = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.abc123-_"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

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)