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

# String: Replace using regular expression

> Replaces part of a string based on the supplied regex.

export const FormField = ({property, label, required = false, diType, uiPatterns, children}) => {
  const patterns = Array.isArray(uiPatterns) ? uiPatterns : uiPatterns ? [uiPatterns] : [];
  return <div style={{
    margin: '1.5rem 0'
  }}>
      <div style={{
    display: 'flex',
    alignItems: 'baseline',
    flexWrap: 'wrap',
    gap: '0.5rem',
    marginBottom: '0.25rem'
  }}>
        <strong>{label}</strong>
        <span style={{
    fontSize: '0.7rem',
    fontWeight: 600,
    textTransform: 'uppercase',
    letterSpacing: '0.04em',
    color: required ? '#6241f5' : '#6b7280'
  }}>
          {required ? 'Required' : 'Optional'}
        </span>
      </div>

      <div>{children}</div>

      {diType || patterns.length > 0 ? <p style={{
    fontSize: '0.85rem',
    color: '#6b7280',
    marginBottom: 0
  }}>
          {diType ? <>
              See the <a href={`/references/${diType}`}>{diType}</a> reference.{' '}
            </> : null}
          {patterns.length > 0 ? <>
              Accepts a <a href={`/documentation/placeholders-and-patterns/patterns#${patterns[0]}`}>pattern</a>.
            </> : null}
        </p> : null}
    </div>;
};

Finds parts of a value using a search pattern and swaps them for something else. This is the flexible version of a find-and-replace: instead of matching one exact phrase, you describe what to look for with a pattern, so you can match things like "any run of spaces", "anything that is not a digit", or "a word followed by a number". Use it to clean up or reformat text in ways a simple search cannot, such as collapsing repeated spaces or stripping out unwanted characters.

This documentation describes: [Schema](/schemas/mapper/string-regex-replace)

## Fields

<FormField property="searchRegex" label="Search regex" required>
  The search pattern that describes what to look for, written as a regular expression (for example `/\s+/` to match any run of whitespace). You can build and test a pattern at [Regex101](https://regex101.com). Every part of the value that matches is replaced.
</FormField>

<FormField property="replace" label="Replace" required>
  The text to put in place of each match. Leave it empty to remove the matched parts entirely. You can refer back to pieces captured in your search pattern (such as `$1`) when the pattern uses capture groups.
</FormField>

## Sample data

| Field        | Value                |
| ------------ | -------------------- |
| Search regex | `/\s+/`              |
| Replace      | ` ` (a single space) |

Input:

```json theme={null}
{ "name": "Wool    scarf   navy" }
```

Output:

```json theme={null}
{ "name": "Wool scarf navy" }
```

```json Configuration theme={null}
{
  "prototype": "string-regex-replace",
  "parameters": {
    "searchRegex": "/\\s+/",
    "replace": " "
  }
}
```
