Identifiersflags: g
MongoDB ObjectId
Match MongoDB ObjectId values — 24-character hexadecimal strings.
Try it in RegexProPattern
regexJavaScript
/\b[0-9a-fA-F]{24}\b/gRaw source: \b[0-9a-fA-F]{24}\b
How it works
Word-bounded exactly 24 hex digits. Case-insensitive character class covers both upper and lower case forms produced by different drivers.
Examples
Input
507f1f77bcf86cd799439011Matches
507f1f77bcf86cd799439011
Input
id: 5f8d0d55b54764421b7156c4Matches
5f8d0d55b54764421b7156c4
Input
not an objectidNo match
—Common use cases
- API log parsing for Mongo-backed services
- Database migration scripts
- Query parameter validation
- Cross-service correlation tracing