Regex for hex color
/#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})\b/gi
Matches
Examples
Note
Accepts 3, 4, 6 and 8 digits: the short and long forms, with and without alpha.
Matches in the example
"#fff""#1e90ff""#0008""#11223344"
Token by token
#the character “#”(?:a group, not capturing[0-9a-f]{3,4}one of: “0” to “9” or “a” to “f”, between 3 and 4 times, as many as possible|or[0-9a-f]{6}one of: “0” to “9” or “a” to “f”, exactly 6 times|or[0-9a-f]{8}one of: “0” to “9” or “a” to “f”, exactly 8 times)end of group\ba word boundary
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