Regex Utilities

Get Hex Color Pattern

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.

API Endpoint

GET /v1/regex/pattern/hex-color

Code Examples

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)

Use via MCP

Add to your AI agent

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"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

What hex color formats does this regex pattern validate?

Validates both short (#RGB) and long (#RRGGBB) hex formats. Examples: #fff, #FFF, #ff0000, #A1B2C3 are valid; fff, #gg0000, #12345 are not.

How do I use this regex pattern in my MCP-enabled editor?

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.

Does the pattern require the hash symbol?

Yes, the pattern enforces the # prefix. Colors without the hash (like 'ffffff') will not match.

Can I modify the returned pattern for different hex formats?

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.

What's the difference between using this vs hardcoding a hex regex?

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.

Try Get Hex Color Pattern Now

Get your free API key and start using Get Hex Color Pattern in seconds.

Get Free API Key