Values
Last updated Oct 1, 2026 When an HTTP request reaches the Cloudflare global network, Cloudflare creates a table of field–value pairs against which to match expressions. This table exists for as long as the current request is being processed.
The values that populate the lookup tables of the Rules language are drawn from a variety of sources:
- Primitive properties are obtained directly from the request (
http.request.uri.path, for example). - Derived values are the product of a transformation, composition, or basic operation. For example, the transformation
lower(http.request.uri.path)converts the value ofhttp.request.uri.pathto lowercase. - Computed values are the product of a lookup, computation, or other intelligence. For example, Cloudflare uses a machine learning process to dynamically calculate attack scores, represented by
cf.waf.score*fields.
Besides these values, expressions may also contain literal values. These are static, known values that you incorporate into expressions to compare them with values from request/response fields with or without any transformations.
When working with values in rule expressions, keep in mind the information in the following sections.
String values and regular expressions
Strings are sequences of bytes enclosed by specific delimiters.
Cloudflare rules support two formats for specifying literal strings, including regular expressions: quoted literal strings and raw strings. These formats have different delimiters and escaping mechanisms.
You can use either of the two string formats to specify regular expressions in an expression. However, Cloudflare recommends that you use the raw string syntax, since the quoted string syntax has complex escaping rules and can lead to unexpected behaviors if not thoroughly tested.
Regular expression matching is performed using the Rust regular expression engine.
Quoted string syntax
When using the quoted string syntax, a string literal is delimited by " (double quote) characters. This format requires that you escape special characters " and \ using \" and \\, respectively.
The quoted string syntax has the following additional escaping requirements:
- When used to specify a regular expression on the right-hand side of the regex operator (
matchesor~), the string is parsed using regex escaping rules. - When used on the right hand-side of expressions with other operators, or in function parameters, the string is parsed using basic escaping rules.
Examplestxt
# Test if URI path contains 'a"b'
http.request.uri.path matches "a\"b"
# Test if URI path contains 'a"#b'
http.request.uri.path matches "a\"#b"
# Replace 'a' with '\' (backslash)
regex_replace(http.host, "a", "\\")
Caution
In some situations you will need to double-escape a string — for example, when using the regex_replace() function with a regular expression matching a backslash (\).
In this case, you must do the basic escaping required by strings as function parameters (using \\ for each \ character) and also the regex escaping (using \\ for each \ character), since the backslash has a special meaning in regular expressions.
Therefore, to replace a backslash (\) with the a character using regex_replace() you would use the following expression:
regex_replace(http.host, "\\\\", "a")
To avoid this situation, Cloudflare recommends that you use the raw string syntax for specifying regular expressions.
Raw string syntax
To specify a string (or regular expression) using the raw string syntax you use special delimiters:
- The initial delimiter is composed of an
rcharacter, optionally followed by one or more#characters (up to 255), followed by a"(double quote) character. - The ending delimiter is a
"(double quote) character followed by the same number of#characters as in the initial delimiter (from 0 to 255).
In a raw string there are no special characters, so all characters up to the ending delimiter are interpreted as is (there are no escape sequences).
Unlike the quoted string syntax, the raw string syntax is always the same, regardless of the context where it is being used (for example, as a regular expression with a regex operator or as a parameter of a function call).
Examplestxt
# Test if URI path contains 'a"b'
http.request.uri.path matches r#"a"b"#
# Test if URI path contains 'a"#b'
http.request.uri.path matches r##"a"#b"##
# Replace '\' (backslash) with 'a'
# You must still escape the '\' character in the following raw string because it has a special meaning in regular expressions
regex_replace(http.host, r"\\", "a")
# Test if URI path ends with '/api/login.aspx'
# You must still escape the '.' character in the following raw string because it has a special meaning in regular expressions ("any character")
http.request.uri.path matches r"/api/login\.aspx$"
Case sensitivity in string comparisons
Since the evaluation of string literal values in expressions is case-sensitive, consider one of the following options to capture capitalization variants in your expression:
- Use the
wildcardoperator, which is case-insensitive, to match a string literal. - Use the
lower()function to convert the string to lowercase before comparison. - Use the
matchesoperator (only available in Business and Enterprise plans) with a regular expression that matches different variants. - Write several sub-expressions with the
eqorcontainsoperator, joined with theoroperator, to capture different variations of the string literal (for example,<field> eq "a" or <field> eq "A").
Regular expression limits
Cloudflare has a few limits in place regarding regular expressions. One of those limits is that each rule supports a maximum of 64 regular expressions (regexes), regardless of your domain's plan.
You can use the following strategies to reduce the number of regular expressions in a rule:
- Use the
containsoperator. - Use the
wildcard/strict wildcardoperators. - Use the
starts_with()andends_with()functions.
Boolean values
Simple expressions using boolean fields do not require operator notations or values. You only need to insert the field on its own, as shown in the ssl example below.
ssl
This simple expression matches requests where the value of the ssl field is true.
To match requests where ssl is false, use the boolean not operator :
not ssl
Arrays
The Cloudflare Rules language includes fields of Array type and functions with Array arguments and return values.
You can access individual array elements using an index (a non-negative value) between square brackets ([]). Array indexes start at 0 (zero).
Use the special notation [*] when specifying an expression that will be evaluated for each array element (like the map high-order function ↗︎). This special index notation will unpack the array, call the enclosing function for all its elements individually, and return a new array containing all the individual return values.
Examples
Consider the http.request.headers.names field with type Array<String> in the following examples:
- Obtain the first element in the array:
http.request.headers.names[0] - Check if the first array element is equal to
Content-Type(case sensitive):
http.request.headers.names[0] == "Content-Type" - Check if any array element is equal to
Content-Type(case sensitive):
any(http.request.headers.names[*] == "Content-Type") - Check if any array element is equal to
Content-Type, ignoring the case:
any(lower(http.request.headers.names[*])[*] == "content-type")
In the last example, the lower() function includes the [*] notation so that the function is evaluated for each array element. This function, used along [*], returns a new array where each element of the input array is converted to lowercase. Then, the string comparison uses [*] to transform the array resulting from applying lower() to each header name into an array of boolean values. Finally, any() evaluates to true if at least one of these array elements is true.
Notes
It is not possible to define your own arrays. You can only use arrays returned by fields, either directly or modified by functions.
