Returns a regex pattern for validating hex colors in both 3-digit (#RGB) and 6-digit (#RRGGBB) formats. Access via MCP in Cursor or Windsurf, or REST at `/v1/regex/pattern/hex-color`. Example output: `^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$`. The pattern enforces proper hex syntax including the required hash prefix and case-insensitive hex digits.
curl "https://tinyfn.io/v1/regex/pattern/hex-color" \
-H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/regex/pattern/hex-color', {
headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests
response = requests.get('https://tinyfn.io/v1/regex/pattern/hex-color',
headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)
Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's regex tools:
{
"mcpServers": {
"tinyfn-regex": {
"url": "https://tinyfn.io/mcp/regex",
"headers": {
"X-API-Key": "YOUR_API_KEY"
}
}
}
}
Validates both short (#RGB) and long (#RRGGBB) hex formats. Examples: #fff, #FFF, #ff0000, #A1B2C3 are valid; fff, #gg0000, #12345 are not.
Call the tool to get the pattern, then use it in your validation logic. In Cursor or Claude Code, the AI can fetch the pattern and help implement color validation for your forms or CSS parsers.
Yes, the pattern enforces the # prefix. Colors without the hash (like 'ffffff') will not match.
The pattern is deterministic and covers standard web hex colors. For custom formats (like removing the # requirement), modify the returned pattern by removing the `#` from the start.
This ensures you get a tested, correct pattern without syntax errors. Useful when AI agents need reliable regex patterns for color validation in generated code.
Get your free API key and start using Get Hex Color Pattern in seconds.
Get Free API Key