From 9a502135925a5a8e3f67ab4ffda9ec5230920a9d Mon Sep 17 00:00:00 2001 From: shifter Date: Mon, 9 Dec 2024 11:26:08 +0100 Subject: [PATCH] news: add entry for regexp-subst Signed-off-by: shifter --- news/fx-feature-409.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 news/fx-feature-409.md diff --git a/news/fx-feature-409.md b/news/fx-feature-409.md new file mode 100644 index 000000000..58cf46b68 --- /dev/null +++ b/news/fx-feature-409.md @@ -0,0 +1,24 @@ +`regex_subst()`: Function Reworked + +The `regex_subst()` function has been updated to enhance functionality: + +- **Extended Match Group Support**: + Replacement strings can now resolve match group references up to 999 groups. + +- **Optional Disabling**: + The feature can be disabled using the `nogroups` named argument flag. + +- **Leading Zero Support**: + Match group references with leading zeros (e.g., `\01`, `\002`) are now correctly interpreted. This prevents ambiguity when parsing group IDs, ensuring that shorter IDs like `\1` are not mistakenly interpreted as part of larger numbers like `\12`. + +**Example**: + +```python +result = regex_subst("baz,foo,bar", /(\w+),(\w+),(\w+)/, "\\2 \\03 \\1") + +# Force disable this feature +result = regex_subst("baz,foo,bar", /(\w+),(\w+),(\w+)/, "\\2 \\03 \\1", nogroups=True) + +# Handling leading zeros +result = regex_subst("baz,foo,bar", /(\w+),(\w+),(\w+)/, "\\0010") # returns `baz0` +```