Skip to content

Commit 22c003b

Browse files
committed
Restructure re.sub docs, clarify aspects of repl notation
- `flags` are only relevant when `pattern` is a string (followup to python#119960). - Moved simplest "beans and spam" example from under "repl is a function" (which it wasn't!) close to start, extended to demonstrate both string & re.compile flags usage, and `\1` templating. - Discuss all how-we-match parameters before what-we-do-with-matches. TODO: Is important info close enough to start? - Explain callback before backslash notation because it's shorter but also to promote it. IMHO, people fear it as a "last-resort escape hatch" while it's actually *simpler* than backslashes (python#128138 is one example). TODO: Will this order make sense after python#135992 ? - Consolidated `repl` notation from two far-away paragraphs to one place. - Starting from `\1` and `\g` which are the whole purpose of dealing with backslashes! - Briefly mention `\octal` wart, 99 limit and `\g<100>` avoiding them. - Draw attention to `\\` for getting a literal backslash. - Clarify that *most* escapes are supported but `\x\u\U\N` aren't. - Move "Unknown escapes of ASCII letters" *after* listing all the known ones. - Added a note promoting raw string notation for `repl` too.
1 parent 03d07dc commit 22c003b

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

Doc/library/re.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ Functions
10891089

10901090
*repl* can be a string template or a function:
10911091

1092-
* If it is a function, it is called for every non-overlapping occurrence of
1092+
* If it is callable, it is called for every non-overlapping occurrence of
10931093
*pattern*. The function takes a single :class:`~re.Match` argument, and
10941094
returns the replacement string. For example::
10951095

0 commit comments

Comments
 (0)