Regex for Base64 String (Strict)
Regex Pattern
^[A-Za-z0-9+/]{4,}(?:={0,2})$Strict base64 encoded string (min 4 chars, proper padding)
Quick Answer
The regex pattern for base64 string (strict) is `^[A-Za-z0-9+/]{4,}(?:={0,2})$`. Strict base64 encoded string (min 4 chars, proper padding). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| SGVsbG8= | ✓ Matches |
| dGVzdA== | ✓ Matches |
| YWJjZGVmZw== | ✓ Matches |
| abc | ✗ No match |
| not*base64! | ✗ No match |
| === | ✗ No match |
Code Examples
javascript
const regex = /^[A-Za-z0-9+\/]{4,}(?:={0,2})$/;
const isValid = regex.test(value);python
import re
pattern = r'^[A-Za-z0-9+/]{4,}(?:={0,2})$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^[A-Za-z0-9+/]{4,}(?:={0,2})$/
if value =~ pattern
puts "valid"
endphp
if (preg_match('/^[A-Za-z0-9+\/]{4,}(?:={0,2})$/', $value)) {
echo "valid";
}java
String pattern = "^[A-Za-z0-9+/]{4,}(?:={0,2})$";
boolean isValid = value.matches(pattern);Frequently Asked Questions
Related Regex Patterns
UUID v4
UUID version 4 (randomly generated)
UUID (Any Version)
Any RFC 4122 UUID (versions 1-5)
JWT Token
JSON Web Token (header.payload.signature)
Hex String
Any-length hexadecimal string
Base64 String
Standard base64 encoded string
Alphanumeric Username
Username with letters, digits, underscores (3-16 chars)