Skip to content

Commit

Permalink
Merge pull request #52 from callowayproject/48-documentation-about-re…
Browse files Browse the repository at this point in the history
…gex-backslash-doubling-doesnt-work-as-expected

Fixed documentation regarding regex config.
  • Loading branch information
coordt authored Aug 16, 2023
2 parents 68dd11b + cd71a1a commit 91e877a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions docsrc/reference/search-and-replace-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,22 @@ version={new_version}"""

Only the search template will use [Python's regular expression syntax](https://docs.python.org/3/library/re.html#regular-expression-syntax) with minor changes. The template string is rendered using the formatting context. The resulting string is treated as a regular expression for searching unless configured otherwise.

Curly braces (`{}`) and backslashes (`\`) must be doubled in the regular expression to escape them from the string formatting process.
Curly braces (`{}`) must be doubled in the regular expression to escape them from the string-formatting process.

If you are using a TOML-formatted configuration file, you must also escape backslashes (`\`) in the regular expression. The TOML parser will treat a single backslash as an escape character.

The following template:

```text
{current_version} date-released: \\d{{4}}-\\d{{2}}-\\d{{2}}
```toml
# TOML-formatted configuration file
search = "{current_version} date-released: \\d{{4}}-\\d{{2}}-\\d{{2}}"
```

or

```ini
# INI-formatted configuration file
search = "{current_version} date-released: \d{{4}}-\d{{2}}-\d{{2}}"
```

Gets rendered to:
Expand Down

0 comments on commit 91e877a

Please sign in to comment.