Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pathvalidate/_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def replace_symbol(
exclude_symbols:
Symbols that were excluded from the replacement.
is_replace_consecutive_chars:
If |True|, replace consecutive multiple ``replacement_text`` characters
to a single character.
If |True|, replace consecutive occurrences of ``replacement_text``
with a single occurrence.
is_strip:
If |True|, strip ``replacement_text`` from the beginning/end of the replacement text.

Expand Down Expand Up @@ -85,7 +85,7 @@ def replace_symbol(
return new_text

if is_replace_consecutive_chars:
new_text = re.sub(f"{re.escape(replacement_text)}+", replacement_text, new_text)
new_text = re.sub(f"(?:{re.escape(replacement_text)})+", replacement_text, new_text)

if is_strip:
new_text = new_text.strip(replacement_text)
Expand Down
8 changes: 8 additions & 0 deletions test/test_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ def test_normal_exclude_symbols(self, value, exclude_symbols, expected):
["!a##b$$$c((((d]]]])", "_", True, False, "_a_b_c_d_"],
["!a##b$$$c((((d]]]])", "_", False, True, "a__b___c____d"],
["!a##b$$$c((((d]]]])", "_", False, False, "_a__b___c____d_____"],
["A!!B", "ab", True, False, "AabB"],
["A!!B", "[]", True, False, "A[]B"],
["A!!B", "あい", True, False, "AあいB"],
["abbbb", "ab", True, False, "abbbb"],
["abab", "ab", True, False, "ab"],
["ababa", "aba", True, False, "ababa"],
["A!!B", "ab", False, False, "AababB"],
["A!!B", "", True, False, "AB"],
],
)
def test_normal_consecutive(
Expand Down