HomeRegex LibraryJSON Web Token (JWT) Format Regex
100% Client-Side β€’ 0 B Data Leaves Browser
security

JSON Web Token (JWT) Format Regex

Validates structure of Base64URL-encoded Header.Payload.Signature JWT strings.

Regular Expression Pattern:
/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/
Valid Match Example:
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozGzN_ce9Trqnh9xsmvrmA6Y8b0VfP_w1sL8sR
Invalid / Non-Match Example:
not-a-jwt-token

Regex Syntax Breakdown & Explanation

  • β€’^[A-Za-z0-9-_=]+ : Base64URL encoded header
  • β€’\. : Period delimiter
  • β€’[A-Za-z0-9-_=]+ : Base64URL encoded payload
  • β€’\.?... : Optional cryptographic signature block

Implementation in Popular Languages

JavaScript / TypeScript
const regex = /^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/;
const isValid = regex.test("eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozGzN_ce9Trqnh9xsmvrmA6Y8b0VfP_w1sL8sR");
console.log(isValid); // true
Python (re)
import re

pattern = r"^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$"
match = re.match(pattern, "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozGzN_ce9Trqnh9xsmvrmA6Y8b0VfP_w1sL8sR")
print(bool(match)) # True
Go (regexp)
package main
import (
  "fmt"
  "regexp"
)

func main() {
  re := regexp.MustCompile(`^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$`)
  fmt.Println(re.MatchString("eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozGzN_ce9Trqnh9xsmvrmA6Y8b0VfP_w1sL8sR"))
}
Frequently Asked Questions

Frequently Asked Questions

Everything you need to know regarding specifications, syntax, and security best practices.

The regular expression pattern is /^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/. Validates structure of Base64URL-encoded Header.Payload.Signature JWT strings.