Regex for Docker Container ID
Regex Pattern
^[0-9a-f]{12}(?:[0-9a-f]{52})?$Docker container ID (short 12 or full 64 hex chars)
Quick Answer
The regex pattern for docker container id is `^[0-9a-f]{12}(?:[0-9a-f]{52})?$`. Docker container ID (short 12 or full 64 hex chars). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| a1b2c3d4e5f6 | ✓ Matches |
| abc123def456 | ✓ Matches |
| a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6abcd | ✓ Matches |
| a1b2c3d4e5 | ✗ No match |
| A1B2C3D4E5F6 | ✗ No match |
| not-hex-chars | ✗ No match |
Code Examples
javascript
const regex = /^[0-9a-f]{12}(?:[0-9a-f]{52})?$/;
const isValid = regex.test(value);python
import re
pattern = r'^[0-9a-f]{12}(?:[0-9a-f]{52})?$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^[0-9a-f]{12}(?:[0-9a-f]{52})?$/
if value =~ pattern
puts "valid"
endphp
if (preg_match('/^[0-9a-f]{12}(?:[0-9a-f]{52})?$/', $value)) {
echo "valid";
}java
String pattern = "^[0-9a-f]{12}(?:[0-9a-f]{52})?$";
boolean isValid = value.matches(pattern);Frequently Asked Questions
Related Regex Patterns
JavaScript Variable Name
Valid JavaScript variable/identifier name
Python Variable Name
Valid Python identifier name
CSS Class Name
Valid CSS class name (starts with letter, underscore, or hyphen)
CSS ID Selector
CSS ID selector starting with #
JSON Key
JSON object key (quoted string followed by colon)
Semantic Version (Strict)
Strict semantic versioning (MAJOR.MINOR.PATCH)