> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Targeting rules

<View title="Developer" />

<View title="Federal docs" />

<View title="EU docs" />

This topic explains how to use flag targeting rules to serve flag variations to different contexts based on their attributes.

## About targeting rules

Targeting rules are the mechanism for expressing precedence and conditions across multiple context kinds. Individual targeting does not support combined logic across context kinds.

Targeting rules, including the default rule, are all listed on a feature flag's **Targeting** tab. You can also use the quick add buttons at the top of the **Targeting** tab to start different kinds of [rollouts](#rollouts) or a new [experiment](/docs/home/experimentation).

Each targeting rule includes a description, one or more conditions, and a rollout.

Each condition has three parts:

* Context **kind** and **attribute** information, which defines the scope of the condition's impact.
  * For segment rules, this is always "context," because segment rules check whether a context is part of a segment.
  * For mobile rules, this is always the application or device context **kind**, and then an **attribute** that you select.
  * For custom rules, this is the context **kind** and **attribute** that you select, such as "user" and "email address." To learn more, read [Attributes](#attributes).
* An **operator**, which sets differentiating characteristics of the attribute, such as limiting the condition to emails that end with certain extensions. If a condition specifies multiple values for the operator to track, the operator iterates over the array. To learn more, read [Operators](#operators).
* A **value**, which identifies the attribute by a value you specify, such as `.edu` or `v1`. For segment rules, these are the segments that you select.

Segment conditions use OR logic. If you select more than one segment in a "Context is in Segments" condition, the condition matches if the context is a member of any one of the selected segments.

Targeting rules are evaluated using the same evaluation model described in [Feature flag hierarchy](/docs/guides/flags/flag-hierarchy).

### Rollouts

The rollout describes what variation of the flag to serve when the end user matches the targeting rule. You can set this to any of the variations of the flag, or to a [percentage rollout](/docs/home/releases/percentage-rollouts). If you want to roll out the selected variation gradually, you can add a [progressive rollout](/docs/home/releases/progressive-rollouts) or [guarded rollout](/docs/home/releases/guarded-rollouts) to the targeting rule. To learn more, read [Releasing features with LaunchDarkly](/docs/home/releases/releasing).

Here is an image of a targeting rule:

<Frame caption="A targeting rule that serves &#x22;Available&#x22; to all user contexts that contain an &#x22;email&#x22; attribute with a value that ends in &#x22;.edu&#x22;.">
  <img src="https://mintcdn.com/launchdarkly/hutarVphEq2dY_zb/images/auto/flag-targeting-rule.auto.png?fit=max&auto=format&n=hutarVphEq2dY_zb&q=85&s=5a390d5737fbf51a235bceb95fd414f2" alt="A targeting rule that serves &#x22;Available&#x22; to all user contexts that contain an &#x22;email&#x22; attribute with a value that ends in &#x22;.edu&#x22;." width="2496" height="464" data-path="images/auto/flag-targeting-rule.auto.png" />
</Frame>

By default, all the targeting rules on the flag's **Targeting** tab are expanded, so that you can view their names and a summary of their conditions. To view only the names of the targeting rules, click the **collapse** icon from the top of the page.

<Note>
  **Targeting rules limitations**

  There is no specific limit on the number of targeting rules you can have on a flag. As a general rule, the SDK initialization time scales with the combination of the total number of flags in the project, the size of the flag variations, and the number and complexity of targeting rules across all flags in the environment. To discuss specifics for your account, [start a Support ticket](https://support.launchdarkly.com/hc/en-us/requests/new).
</Note>

### Attributes

LaunchDarkly allows you to create your own attributes. For instance, you might want to target contexts based on plan, group, role, or location.

Here is an example of a context with custom attribute values, though each SDK sends context data to LaunchDarkly in a slightly different format:

<CodeGroup>
  ```json title="A context with custom attributes" lines wrap theme={null}
  {
    "kind": "user",
    "name": "Sandy",
    "email": "sandy@example.com",
    "gymMember": true
  }
  ```
</CodeGroup>

Using attributes, you could show some features to customers on your regular plan, and additional features to customers on your premium plan. Or you could roll out a new feature to 30% of end users at a particular location, rather than 30% of all end users. To learn more, read [Context attributes](/docs/home/flags/context-attributes).

In each targeting rule, you can choose an attribute specific to your chosen context kind using the "Attribute" menu.

<Frame caption="The &#x22;Attribute&#x22; menu, showing attributes for a user context.">
  <img src="https://mintcdn.com/launchdarkly/A4UXoRTW8ATNw4yq/images/auto/targeting-attribute-dropdown.auto.png?fit=max&auto=format&n=A4UXoRTW8ATNw4yq&q=85&s=ccfccd2bbfd1bc12b0a90b296df012f9" alt="The &#x22;Attribute&#x22; menu, showing attributes for a user context." width="2020" height="320" data-path="images/auto/targeting-attribute-dropdown.auto.png" />
</Frame>

If an attribute is an object, then in your targeting you can use `/` as a delimiter to refer to specific object fields. For example, if you have an "address" attribute that includes "city," "state," and several other fields, then you can use `/address/city` in your targeting.

From here, you can also select whether to include or exclude all contexts of a particular context kind based on whether they are part of a segment. To learn more, read [Segments](/docs/home/flags/segments).

### Operators

LaunchDarkly supports the following operators:

<table>
  <thead>
    <tr>
      <th>Operator</th>
      <th>Attribute type</th>
      <th>Meaning</th>
      <th>[JSON value](/docs/home/flags/json-targeting)</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>is one of (=), is not one of (!=)</td>
      <td>string, number, boolean, date</td>
      <td>Exact match</td>
      <td>`in`</td>
    </tr>

    <tr>
      <td>ends with, does not end with</td>
      <td>string</td>
      <td>String suffix match</td>
      <td>`endsWith`</td>
    </tr>

    <tr>
      <td>starts with, does not start with</td>
      <td>string</td>
      <td>String prefix match</td>
      <td>`startsWith`</td>
    </tr>

    <tr>
      <td>matches regex, does not match regex</td>
      <td>string</td>
      <td>Regular expression match</td>
      <td>`matches`</td>
    </tr>

    <tr>
      <td>contains, does not contain</td>
      <td>string</td>
      <td>Substring match</td>
      <td>`contains`</td>
    </tr>

    <tr>
      <td>greater than (>), less than (\<), greater than or equal to (>=), less than or equal to (\<=)</td>
      <td>number</td>
      <td>Numeric comparisons</td>

      <td>
        `greaterThan`<br />
        `lessThan`<br />
        `greaterThanOrEqual`<br />
        `lessThanOrEqual`
      </td>
    </tr>

    <tr>
      <td>before, after</td>
      <td>date</td>
      <td>Date comparisons. Dates must be formatted in UNIX milliseconds or a string in RFC-3339 format. To learn more, read [Representations of date/time values](/docs/sdk/concepts/flag-types#representations-of-date/time-values).</td>

      <td>
        `before`<br />
        `after`
      </td>
    </tr>

    <tr>
      <td>semantic version is one of (=), is not one of (!=), greater than (>), less than (\<), greater than or equal to (>=), less than or equal to (\<=)</td>
      <td>string</td>

      <td>
        Compares values as semantic versions in the format <code>MAJOR.MINOR.PATCH</code>. LaunchDarkly accepts versions without a PATCH, such as <code>2.0</code>.
      </td>

      <td>
        `semVerEqual`<br />
        `semVerGreaterThan`<br />
        `semVerLessThan`<br />
        For "greater than or equal to," use `semVerLessThan` and set `negate` to `true`<br />
        For "less than or equal to," use `semVerGreaterThan` and set `negate` to `true`
      </td>
    </tr>

    <tr>
      <td>is in, is not in ([segments only](/docs/home/flags/segment-targeting#target-segments))</td>
      <td>segment name</td>
      <td>Exact match. If you list more than one segment, LaunchDarkly considers the condition met if the context is in/is not in at least one of the segments.</td>
      <td>`segmentMatch`</td>
    </tr>
  </tbody>
</table>

Semantic versions follow the format `MAJOR.MINOR.PATCH`, such as `1.2.3`. The PATCH number is optional, so `2.0` and `2.0.1` are both valid. For some operators, LaunchDarkly stores comparisons internally as the inverse. For example, "≥" is stored as "not \<," and "≤" is stored as "not >." To learn more, read [Semantic versions](/docs/sdk/concepts/flag-types#semantic-versions).

### Regular expression compatibility across SDKs

LaunchDarkly supports regular expressions for the **matches regex** and **does not match regex** operators. Because regular expression syntax varies between programming languages, regex behavior can differ depending on where your flag is evaluated.

* **Server-side SDKs:** Regular expressions are evaluated using the regex engine of the SDK language. For example, the Java SDK uses `java.util.regex`, and the Go SDK uses Go’s `regexp` package.
* **Client-side SDKs:** Regular expressions are evaluated by LaunchDarkly’s backend:
  * If the expression conforms to Perl syntax, LaunchDarkly evaluates it with a Rust-based regex engine.
  * If it does not conform to Perl syntax, LaunchDarkly evaluates it with a Go-based regex engine.

Neither the Rust nor Go regex engines support lookahead or lookbehind assertions. These patterns do not work in LaunchDarkly targeting rules.

To ensure consistent results across SDKs and environments, use only syntax features that are supported by all relevant regex engines. For most use cases, the safest option is to use simple expressions such as `.`, `*`, `[ ]`, `^`, and `$`. If your implementation relies on more advanced syntax, test your expressions with the specific SDKs and environments you use before deploying them.

## Types of targeting

LaunchDarkly supports the following targeting types:

* [Targeting segments](/docs/home/flags/segment-targeting)
* [Individual targeting](/docs/home/flags/individual-targeting)
* [Bulk targeting](/docs/home/flags/bulk-targeting)
* [Mobile targeting](/docs/home/flags/mobile-targeting)
* [Custom rules](/docs/home/flags/custom-rules)

Each flag can include up to 5,000 targeting rules and 50,000 values across all rules.

You can also set flag prerequisites to make flags depend on other flags being enabled to take effect. To learn more, read [Flag prerequisites](/docs/home/flags/prereqs).
