- Cookie Value
- Country Code (2 letter)
- Country State Code
- File Extension
- Origin Retry Attempt Count
- Query String
- Random Chance (%)
- Remote IP
- Request Header
- Request Method
- Request URL
- Response Header
- Response Status Code
- Streaming manifests
- Versioned build assets
- Dynamically generated API routes
Using Pattern Matching
Pattern matching can be used in any Edge Rule condition that evaluates a request value. To enable pattern matching, prefix the value with:pattern: prefix instructs the Edge Rule engine to evaluate the
value using Lua pattern matching instead of a standard string
comparison.
Lua patterns are similar to regular expressions but intentionally
simpler and optimized for performance.
Anchoring the Pattern
Patterns should normally be wrapped with:pattern: prefix is not used, the condition behaves as a normal
string comparison.
Example
Pattern:string.find
function. This provides efficient pattern matching without requiring a
full regular expression engine.
Example Use Cases
Matching Streaming Manifests
Streaming platforms often generate manifest files containing region identifiers or session identifiers in the filename. Example URLs:- Custom cache control
- Edge redirects
- Request routing
Targeting Versioned Assets
Many build systems generate versioned assets:- Cache rules
- Rate limiting
- Header modification
Security Filtering
Pattern matching can also be used in security rules. Example scenarios:- Blocking administrative endpoints
- Detecting suspicious request patterns
- Filtering specific URL structures
Lua Pattern Cheat Sheet
Edge Rules use Lua patterns, which are simpler than full regular expressions.Format
string.find.
Anchors
Character Classes
Repeaters
Escaping Characters
Use% to escape special characters.
Examples:
Limitations
Lua patterns are intentionally simpler than full regular expressions. Unsupported features include:- Alternation (
|) - Lookaheads / lookbehinds
- Full PCRE syntax