REGEX Examples with explanations

A string 24 characters in length and only with hexadecimal letters and numbers

Example use: In MongoDb the unique id’s (ObjectId)

The string must be 24 characters long. ^ Starts of string or start of line, $ end of string or line; both dependent on the “multi-line mode”

/^{24}$/

Hexadecimal uses only the letters “a to f” and the number “0 to 9”

/^[a-f0-9]{24}$/

Comments are closed.