> For the complete documentation index, see [llms.txt](https://docs.specifyapp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.specifyapp.com/reference/parsers/select-modes-3.md).

# replace-string

## Interface

```typescript
interface parser {
  name: 'replace-string';
  options: ({
    all?: string | {
      regex: string | { pattern: string, flags?: 'g' & 'm' & 'i' },
      replaceBy: string
    }
  } | 
  {
    group?: string | {
      regex: string | { pattern: string, flags?: 'g' & 'm' & 'i' },
      replaceBy: string
    };
    collection?: string | {
      regex: string | { pattern: string, flags?: 'g' & 'm' & 'i' },
      replaceBy: string
    };
    token?: string | {
      regex: string | { pattern: string, flags?: 'g' & 'm' & 'i' },
      replaceBy: string
    }
  }) & { applyTo?: SDTFQuery }
}
```

## Options

<table><thead><tr><th width="170">Parameter</th><th width="127.33333333333331">Required</th><th width="330">Type</th><th width="179">Default</th><th width="253">Description</th></tr></thead><tbody><tr><td><code>all</code></td><td><code>false</code></td><td><pre class="language-typescript"><code class="lang-typescript">string | {
  regex: string | { pattern: string, flags: 'g' &#x26; 'm' &#x26; 'i' },
  replaceBy: string
}
</code></pre></td><td></td><td>Select all collections, groups and tokens in your SDTF token graph.</td></tr><tr><td><code>group</code></td><td><code>false</code></td><td><pre class="language-typescript"><code class="lang-typescript">string | {
  regex: string | { pattern: string, flags: 'g' &#x26; 'm' &#x26; 'i' },
  replaceBy: string
}
</code></pre></td><td></td><td>Select all groups in your SDTF token graph.</td></tr><tr><td><code>collection</code></td><td><code>false</code></td><td><pre class="language-typescript"><code class="lang-typescript">string | {
  regex: string | { pattern: string, flags: 'g' &#x26; 'm' &#x26; 'i' },
  replaceBy: string
}
</code></pre></td><td></td><td>Select all collections in your SDTF token graph.</td></tr><tr><td><code>token</code></td><td><code>false</code></td><td><pre class="language-typescript"><code class="lang-typescript">string | {
  regex: string | { pattern: string, flags: 'g' &#x26; 'm' &#x26; 'i' },
  replaceBy: string
}
</code></pre></td><td></td><td>Select all tokens in your SDTF token graph.</td></tr><tr><td>regex</td><td><code>required</code></td><td><code>object | string</code></td><td></td><td>If string: the parameter used for the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#literal_notation_and_constructor">constructor of the regex</a>. If your use case need to use flags prefer object notation.</td></tr><tr><td>regex.pattern</td><td><code>required</code></td><td><code>string</code></td><td></td><td>The pattern of the regex used as first argument of the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#literal_notation_and_constructor">constructor</a>.</td></tr><tr><td>regex.flags</td><td><code>false</code></td><td><code>string</code></td><td></td><td>The flags to use for regex. In the regex constructor it's the second argument <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#literal_notation_and_constructor">constructor of the regex</a>.</td></tr><tr><td>replaceBy</td><td><code>required</code></td><td><code>string</code></td><td></td><td>The value will used as replacement. <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/String/replace">This method</a> is used to apply the replacement.</td></tr><tr><td><code>trim</code></td><td><code>false</code></td><td><code>boolean</code></td><td><code>false</code></td><td>Set true to remove spaces before and after the transformed values. <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/String/Trim">This method</a> is used to trim.</td></tr><tr><td><code>applyTo</code></td><td><code>false</code></td><td><pre class="language-typescript"><code class="lang-typescript">| { collection: string | true }
| { group: string | true }
| { token: string | true }
| SDTFQuery
</code></pre></td><td></td><td>The selection where to apply the transformation.<br><br><code>collection</code>, <code>group</code>, <code>token</code> take a Regex string or <code>true</code> to select anything of the kind.<br><br>An <a href="/pages/o67KwpWZQBri4JwW36gc#introduction"><code>SDTFQuery</code></a> can be used for advance use cases.</td></tr></tbody></table>

## Basic usage: Rename design token by keeping only characters present after the last slash character (`/`).

{% tabs %}
{% tab title="Input" %}

<pre class="language-json" data-line-numbers><code class="lang-json">{
  "colors": {
<strong>    "Colors/Black": {
</strong>      "$type": "color",
      "$value": {
        "default": {
          "model": "hex",
          "hex": "#000000",
          "alpha": 1
        }
      }
    }
  }
}
</code></pre>

{% endtab %}

{% tab title="Config" %}
{% code title=".specifyrc.json" lineNumbers="true" %}

```json5
{
  "version": "2",
  "repository": "@organization/repository",
  // Only use the personalAccessToken when working with the CLI
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "Rename tokens",
      "parsers": [
        {
          "name": "replace-string",
          "options": {
            "token": {
              "regex": {
                "pattern": "(.*?)\\/",
                "flags": "g"
              },
              "replaceBy": ""
            }
          }
        },
        {
          "name": "to-sdtf",
          "output": {
            "type": "file",
            "filePath": "tokens.json"
          }
        }
      ]
    }
  ]
}
```

{% endcode %}
{% endtab %}

{% tab title="Output" %}

<pre class="language-css" data-title="tokens.json" data-line-numbers><code class="lang-css">{
  "colors": {
<strong>    "Black": {
</strong>      "$type": "color",
      "$value": {
        "default": {
          "model": "hex",
          "hex": "#000000",
          "alpha": 1
        }
      }
    }
  }
}
</code></pre>

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.specifyapp.com/reference/parsers/select-modes-3.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
