You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docsrc/reference/search-and-replace-config.md
+24-4
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
# Searching and replace configuration
1
+
# Search and replace configuration
2
2
3
-
Bump-my-version uses [template strings](https://docs.python.org/3/library/string.html#format-string-syntax) to search the configured files for the old or current version and replace the text with the new version.
3
+
Bump-my-version uses a combination of [template strings](https://docs.python.org/3/library/string.html#format-string-syntax) using a [formatting context](formatting-context.md) and regular expressions to search the configured files for the old or current version and replace the text with the new version.
4
4
5
-
You can configure the search or replace templates globally and within each `tool.bumpversion.files` entry in your configuration.
5
+
## Using template strings
6
6
7
-
The default search template is `{current_version}` to find the version string within the file and replace it with `{new_version}`.
7
+
Both the search and replace templates are rendered using the [formatting context](formatting-context.md). However, only the search template is also treated as a regular expression. The replacement fields available in the formatting context are enclosed in curly braces `{}`.
8
8
9
9
The search and replace templates can be multiple lines, like so:
10
10
@@ -34,3 +34,23 @@ replace = """
34
34
[myproject]
35
35
version={new_version}"""
36
36
```
37
+
38
+
## Using regular expressions
39
+
40
+
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.
41
+
42
+
Curly braces (`{}`) and backslashes (`\`) must be doubled in the regular expression to escape them from the string formatting process.
0 commit comments