Regex for base64
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm
Matches
Examples
Note
Checks the alphabet and padding. Plenty of ordinary words are valid Base64 too, so a match is not proof.
Matches in the example
"aGVsbG8=""SGVsbG8sIHdvcmxkIQ=="
Token by token
^the start of the string (or line, with the m flag)(?:a group, not capturing[A-Za-z0-9+/]{4}one of: “A” to “Z”, “a” to “z”, “0” to “9”, “+” or “/”, exactly 4 times)*end of group, whole group zero or more times, as many as possible(?:a group, not capturing[A-Za-z0-9+/]{2}one of: “A” to “Z”, “a” to “z”, “0” to “9”, “+” or “/”, exactly 2 times==the text “==”|or[A-Za-z0-9+/]{3}one of: “A” to “Z”, “a” to “z”, “0” to “9”, “+” or “/”, exactly 3 times=the character “=”)?end of group, whole group optionally$the end of the string (or line, with the m flag)
Other patterns
- Email address
- URL
- IPv4 address
- UUID
- Hex color
- Date (YYYY-MM-DD)
- Time (24-hour)
- US phone number
- Phone number (E.164)
- US ZIP code
- Credit card number
- URL slug
- Username
- Strong password
- HTML tag
- Semantic version
- MAC address
- JSON Web Token
- Hashtag
- @mention
- Number
- Leading and trailing whitespace
- Repeated word
- Blank lines
- Markdown link
- Quoted string
- Domain name
- File extension
- Base64
- Trailing comma