# Trabalhando com expressões

{% hint style="danger" %}
Por favor, observe que o tempo de execução de uma expressão regular é de 5 segundos.
{% endhint %}

findall() | similar()

<mark style="color:vermelho;">**LEGENDA:**</mark>

<mark style="color:vermelho;">**!**</mark> - Parâmetros obrigatórios

#### <mark style="color:padrão;background-color:blue;">Pesquisar em uma string usando uma expressão regular</mark>

**findall(reg, str, index) -** para encontrar todas as correspondências de grupos em uma string

Parâmetros:

<mark style="color:vermelho;">**!**</mark>**&#x20;reg** - expressão regular

<mark style="color:vermelho;">**!**</mark>**&#x20;str** -  string na qual a busca é realizada

&#x20;**index** - índice do resultado encontrado. Ele começa em zero. Isso significa que o primeiro resultado encontrado tem índice 0.

<mark style="color:padrão;background-color:blue;">**Comparação de strings com tolerância a erros de digitação**</mark>

**similar(str1, str2)** - compara duas strings permitindo erros de digitação. Retorna True se as strings diferirem em menos de 30%.

<details>

<summary>Exemplo</summary>

Vamos ver um exemplo de busca por uma string usando uma expressão regular especificada:

<div data-with-frame="true"><figure><img src="/files/f5ab71ebf86b7dda287a2cc3c81114cbd934c2dc" alt="" width="375"><figcaption></figcaption></figure></div>

O resultado é o seguinte:

<div data-with-frame="true"><figure><img src="/files/2d4976382626c306ce046a81f8d80ae3bb0fa730" alt="" width="375"><figcaption></figcaption></figure></div>

Exemplo de uso da função de comparação de strings com tolerância a erros de digitação:&#x20;

No bloco inicial, adicionamos nosso enigma na seção de mensagem. Em seguida, também adicionamos a resposta ao nosso enigma na calculadora usando a variável:

**riddle = 'cold'.**

No segundo bloco, inserimos a seguinte expressão na calculadora:

**response = if(similar(riddle, question) == True, "super!", "Nãooo! é um #{riddle}").**

Não se esqueça de adicionar **#{response}** à seção de mensagem.

<div data-with-frame="true"><figure><img src="/files/c5855d27743f36456f1cbae67209fb9c4c67ddba" alt="" width="375"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/c8dab467903afde6294d8c200cad0940e082f7ab" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/fe1b9228c05e495e224d2192ebf1de4c3dd09f24" alt="" width="375"><figcaption></figcaption></figure></div>

</details>

<details>

<summary>Código</summary>

<pre><code><strong>a = findall('.ai\/(.+)\/', 'https://payform.com/ab252acn/', 0)
</strong>
response = if(similar(riddle, question) == True , "super!", "Nãooo! é um #{riddle}")
</code></pre>

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mavibot.ai/doc/pt/chatbot/functions/calculadora/expressions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
