diff options
| author | 2020-02-26 13:26:06 +0000 | |
|---|---|---|
| committer | 2020-02-26 13:26:06 +0000 | |
| commit | 7ebad30c2f00bf7aea582a47a6b27848552f055d (patch) | |
| tree | 32f57ca70265fd0a556e77534c658d81e0bb1ab2 /src | |
| parent | update CHANGELOG.md (diff) | |
| signature | ||
convert & in sed to \g<0> so python handles full-match replacements
Diffstat (limited to 'src')
| -rw-r--r-- | src/utils/parse/sed.py | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/utils/parse/sed.py b/src/utils/parse/sed.py index 75d24be4..76b9e567 100644 --- a/src/utils/parse/sed.py +++ b/src/utils/parse/sed.py @@ -26,16 +26,10 @@ class SedReplace(Sed): count: int def match(self, s): - matches = list(self.pattern.finditer(s)) - if not self.count == 0: - matches = matches[:self.count] - - for match in matches: - replace_copy = self.replace - for token in reversed(_tokens(replace_copy, "&")): - replace_copy = ( - replace_copy[:token]+match.group(0)+replace_copy[token+1:]) - s = re.sub(self.pattern, replace_copy, s, 1) + replace_copy = self.replace + for token in reversed(_tokens(replace_copy, "&")): + replace_copy = replace_copy[:token]+r"\g<0>"+replace_copy[token+1:] + s = re.sub(self.pattern, replace_copy, s, self.count) return s @dataclasses.dataclass |
