# Match entities

A match entity can be detected anywhere in the conversation, meaning it is context-independent.&#x20;

## Detect information anywhere

Entities can always be asked inside a [Collect input](https://docs.chatlayer.ai/buildabot/flow-logic/dialog-state/user-input-bot-dialog) block, but **match entities** can be detected anywhere in the conversation, which means they will skip the **Collect input** block in your flow. This would result in a conversation like this one:

![The bot now recognises the package number without asking for it](https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LLTwFwbOqJj4dDhg8Ju%2F-MaiD56xtmTUFIr6h-ih%2F-MaiGwIaqkWo_1l4CE6q%2Fmatchh.png?alt=media\&token=3ada077d-fc7e-4aea-bdae-1a8b3e99f683)

Because you predefined the package number as a match entity, the bot was able to pick up on it in the user's expression, therefore skipping the Collect input block asking for it. The result is a much better user experience and a seemingly smarter bot 😉

## Match text or patterns

Match entities have 2 options:

* to match a [text](#match-text)
* to match a [pattern](#match-pattern)

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F2AMsXIFh3byDdzlQxGH5%2FScreenshot%202024-08-14%20at%2015.56.55.png?alt=media&#x26;token=7ce4720a-ac59-49fd-bd5b-1b49c03e6488" alt=""><figcaption><p>Match entities example.</p></figcaption></figure>

{% hint style="warning" %}
Note that match entities are context-independent, meaning that they can be detected at any place in the conversation. Therefore, they are very different from [contextual entities ](https://docs.chatlayer.ai/nlp/natural-language-processing-nlp/detect-information-with-entities/contextual-entities)which are context-dependent and can be detected only at certain places inside the conversation.
{% endhint %}

### Add a match text entity

A match text entity will be detected when what the user says matches a value in a pre-defined list.

To add a Match text entity:

1. From the [Entities](https://docs.chatlayer.ai/navigation/natural-language-processing-nlp/synonym-entities) tab, click on the **Add match entity** button.
2. Select **Match text**.
3. Enter an **Entity name**.
4. Enter different **Entity values**.
5. If you want to, add [**Synonyms**](#synonyms-in-match-text-entities) to these values by typing them in the field then clicking `Enter` on your keyboard.

<details>

<summary>Synonyms in match text entities</summary>

For each value of a matched text, you can add a synonym that will be detected as the original value. Synonyms allow you to add alternatives to entities that are assigned to the same value.&#x20;

For example:

*I want to go to Brussels*

*I want to go to Bruxelles*

The meaning of the two expressions above is exactly the same, but you want to convert *Bruxelles* to *Brussels* so your bot can work with one and the same value.

Note that match entities are case insensitive, so there's no need to add capitalized synonyms.

</details>

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FEYlHyObSJeCzeSjzaD02%2FScreenshot%202024-08-14%20at%2016.02.00.png?alt=media&#x26;token=301e3488-8d41-42e4-b8d8-1daa68e46454" alt="" width="563"><figcaption><p>Add a match text entity.</p></figcaption></figure>

6. Click on **Create entity**.

When a user says "I want to know more about the **Premium** pack", the match entity **@product** will be recognized and saved with the value "Premium".

### Add a match pattern entity

A match pattern entity will be detected when what the user says matches a certain regular pattern.

To add a match pattern entity:

1. From the [Entities](https://docs.chatlayer.ai/navigation/natural-language-processing-nlp/synonym-entities) tab, click on the **Add match entity** button.
2. Select **Match pattern**.
3. Add an **Entity name**.
4. Add a regular expression under **Pattern**.

<details>

<summary>Regular expressions in match pattern entities</summary>

The pattern that you fill in match pattern entities should be written as a regular expression (RegEx) Python style. For more information check <https://regex101.com/>.

For example: you have defined **@customer\_ID** as a match entity, and have provided the following regex pattern: `[a-z]{5}[0-9]{2}`. This means that when a users says "My customer ID is terwf33" – which consists of 5 letters and 2 numbers – it is saved as the match entity **@customer\_ID** with the value "terwf33".

</details>

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2Fl3CqPG86ZNWARIdoHlkM%2FScreenshot%202024-08-14%20at%2016.08.59.png?alt=media&#x26;token=b2e79b1f-31bf-4572-b951-97ddda09a561" alt="" width="563"><figcaption><p>Add a match pattern entity.</p></figcaption></figure>
