---
title: switch
page-cloud: true
latest-operator-version: v26.2.6
latest-console-tag: v3.14.0
latest-connect-version: 4.118.0
latest-redpanda-tag: v26.2.7
docname: connect/components/scanners/switch
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: connect/components/scanners/switch.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/develop/pages/connect/components/scanners/switch.adoc
description: Select a child scanner dynamically for source data based on factors such as the filename.
page-context-switcher:
  - name: Scanner
    to: /cloud-data-platform/develop/connect/components/scanners/switch/
  - name: Output
    to: /cloud-data-platform/develop/connect/components/outputs/switch/
  - name: Processor
    to: /cloud-data-platform/develop/connect/components/processors/switch/
page-self-managed-available: "true"
page-self-managed-available-url: https://docs.redpanda.com/connect/components/scanners/switch/
page-git-created-date: "2024-09-09"
page-git-modified-date: "2026-10-19"
page-generated-sources:
  - include: connect:components:partial$descriptions/scanners/switch.adoc
    generator: null
    version: null
    source: the component specs in https://github.com/redpanda-data/connect
page-generated-content: partial
---

# switch

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

<!-- Source: https://docs.redpanda.com/cloud-data-platform/develop/connect/components/scanners/switch.md -->

Select a child scanner dynamically for source data based on factors such as the filename.

This scanner outlines a list of potential child scanner candidates to be chosen, and for each source of data the first candidate to pass will be selected. A candidate without any conditions acts as a catch-all and will pass for every source, it is recommended to always have a catch-all scanner at the end of your list. If a given source of data does not pass a candidate an error is returned and the data is rejected.

#### Common

```yml
scanner:
  switch:
    - re_match_name: "" # No default (optional)
      scanner: {} # No default (required)
```

#### Advanced

```yml
scanner:
  switch:
    - re_match_name: "" # No default (optional)
      scanner: {} # No default (required)
```

## Fields

### `re_match_name`

A regular expression to test against the name of each source of data fed into the scanner (filename or equivalent). If this pattern matches the child scanner is selected.

**Type**: `string`

### `scanner`

The scanner to activate if this candidate passes.

**Type**: `scanner`

## Examples

### Switch based on file name

In this example a file input chooses a scanner based on the extension of each file

```yaml
input:
  file:
    paths: [ ./data/* ]
    scanner:
      switch:
        - re_match_name: '\.avro$'
          scanner: { avro: {} }

        - re_match_name: '\.csv$'
          scanner: { csv: {} }

        - re_match_name: '\.csv.gz$'
          scanner:
            decompress:
              algorithm: gzip
              into:
                csv: {}

        - re_match_name: '\.tar$'
          scanner: { tar: {} }

        - re_match_name: '\.tar.gz$'
          scanner:
            decompress:
              algorithm: gzip
              into:
                tar: {}

        - scanner: { to_the_end: {} }
```