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

# Regex Tools

> Match, extract, replace, split, and validate using regular expressions.

The Regex Tools connector provides regular expression operations for pattern matching, extraction, and text manipulation.

<Note>No connection required; this utility connector works out of the box.</Note>

## Tools

<AccordionGroup>
  <Accordion title="match: Find all matches">
    <ParamField body="text" type="string" required>
      Text to search.
    </ParamField>

    <ParamField body="pattern" type="string" required>
      Regular expression pattern.
    </ParamField>

    <ParamField body="flags" type="string" default="g">
      Regex flags (e.g., `g`, `i`, `m`).
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "text": "Contact us at support@example.com or sales@example.com",
      "pattern": "[\\w.+-]+@[\\w-]+\\.[\\w.]+",
      "flags": "g"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "count": 2,
      "matches": [
        "support@example.com",
        "sales@example.com"
      ]
    }
    ```
  </Accordion>

  <Accordion title="extract: Extract capture groups">
    <ParamField body="text" type="string" required>
      Text to search.
    </ParamField>

    <ParamField body="pattern" type="string" required>
      Pattern with capture groups.
    </ParamField>

    <ParamField body="flags" type="string" default="g">
      Regex flags.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "text": "Order #1234 placed on 2026-04-02, Order #5678 placed on 2026-04-03",
      "pattern": "Order #(\\d+) placed on (\\d{4}-\\d{2}-\\d{2})",
      "flags": "g"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "matches": [
        {
          "fullMatch": "Order #1234 placed on 2026-04-02",
          "groups": ["1234", "2026-04-02"],
          "index": 0
        },
        {
          "fullMatch": "Order #5678 placed on 2026-04-03",
          "groups": ["5678", "2026-04-03"],
          "index": 34
        }
      ],
      "count": 2
    }
    ```
  </Accordion>

  <Accordion title="replace: Replace by regex">
    <ParamField body="text" type="string" required>
      Source text.
    </ParamField>

    <ParamField body="pattern" type="string" required>
      Regex pattern.
    </ParamField>

    <ParamField body="replacement" type="string" required>
      Replacement string. Use `$1`, `$2` for capture groups, `$&` for full match.
    </ParamField>

    <ParamField body="flags" type="string" default="g">
      Regex flags.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "text": "2026-04-02",
      "pattern": "(\\d{4})-(\\d{2})-(\\d{2})",
      "replacement": "$2/$3/$1"
    }
    ```

    **Example response:**

    ```json theme={null}
    { "result": "04/02/2026", "replacements": 1 }
    ```
  </Accordion>

  <Accordion title="split: Split by regex">
    <ParamField body="text" type="string" required>
      Text to split.
    </ParamField>

    <ParamField body="pattern" type="string" required>
      Regex pattern.
    </ParamField>

    <ParamField body="limit" type="number">
      Maximum number of splits.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "text": "apple;; banana, cherry  orange",
      "pattern": "[;,\\s]+"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "parts": ["apple", "banana", "cherry", "orange"],
      "count": 4
    }
    ```
  </Accordion>

  <Accordion title="test: Test if pattern matches">
    Returns `true` or `false`.

    <ParamField body="text" type="string" required>
      Text to test.
    </ParamField>

    <ParamField body="pattern" type="string" required>
      Regex pattern.
    </ParamField>

    <ParamField body="flags" type="string" default="">
      Regex flags.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "text": "192.168.1.100",
      "pattern": "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$"
    }
    ```

    **Example response:**

    ```json theme={null}
    { "matches": true }
    ```
  </Accordion>

  <Accordion title="escape: Escape special characters">
    Escape regex special characters so a string can be used as a literal pattern.

    <ParamField body="text" type="string" required>
      Text to escape.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "text": "price is $9.99 (USD)"
    }
    ```

    **Example response:**

    ```json theme={null}
    { "result": "price is \\$9\\.99 \\(USD\\)" }
    ```
  </Accordion>

  <Accordion title="validate: Check if regex is valid">
    <ParamField body="pattern" type="string" required>
      Regex pattern to validate.
    </ParamField>

    <ParamField body="flags" type="string" default="">
      Regex flags.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "pattern": "[a-z",
      "flags": "g"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "valid": false,
      "error": "Invalid regular expression: /[a-z/: Unterminated character class"
    }
    ```
  </Accordion>

  <Accordion title="count: Count matches">
    <ParamField body="text" type="string" required>
      Text to search.
    </ParamField>

    <ParamField body="pattern" type="string" required>
      Regex pattern.
    </ParamField>

    <ParamField body="flags" type="string" default="g">
      Regex flags.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "text": "the cat sat on the mat",
      "pattern": "\\b\\w{3}\\b",
      "flags": "g"
    }
    ```

    **Example response:**

    ```json theme={null}
    { "count": 5 }
    ```
  </Accordion>

  <Accordion title="positions: Find match positions">
    Returns start and end positions of each match.

    <ParamField body="text" type="string" required>
      Text to search.
    </ParamField>

    <ParamField body="pattern" type="string" required>
      Regex pattern.
    </ParamField>

    <ParamField body="flags" type="string" default="g">
      Regex flags.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "text": "Error on line 12, error on line 45",
      "pattern": "\\d+",
      "flags": "g"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "positions": [
        { "match": "12", "start": 14, "end": 16 },
        { "match": "45", "start": 32, "end": 34 }
      ],
      "count": 2
    }
    ```
  </Accordion>
</AccordionGroup>
