replace_regex
Replace content in files using regular expressions, with optional handling of multiple matches and wildcard patterns for large code sections.
Instructions
Replaces one or more occurrences of the given regular expression. This is the preferred way to replace content in a file whenever the symbol-level tools are not appropriate. Even large sections of code can be replaced by providing a concise regular expression of the form "beginning.*?end-of-text-to-be-replaced". Always try to use wildcards to avoid specifying the exact content of the code to be replaced, especially if it spans several lines.
IMPORTANT: REMEMBER TO USE WILDCARDS WHEN APPROPRIATE! I WILL BE VERY UNHAPPY IF YOU WRITE LONG REGEXES WITHOUT USING WILDCARDS INSTEAD!.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repl | Yes | The string to replace the matched content with, which may contain backreferences like \1, \2, etc. Make sure to escape special characters appropriately, e.g., use `\\n` for a literal `\n`. | |
| regex | Yes | A Python-style regular expression, matches of which will be replaced. Dot matches all characters, multi-line matching is enabled. | |
| relative_path | Yes | The relative path to the file. | |
| allow_multiple_occurrences | No | If True, the regex may match multiple occurrences in the file and all of them will be replaced. If this is set to False and the regex matches multiple occurrences, an error will be returned (and you may retry with a revised, more specific regex). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |