Skip to content

Commit 72017f4

Browse files
committed
Fixed an issue in tester where the reason string would an extra espace sequence attached
1 parent b8243fd commit 72017f4

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/rexplain/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.2.4"
1+
__version__ = "0.2.5"
22

33
from .core.explainer import RegexExplainer
44
from .core.generator import ExampleGenerator

src/rexplain/core/tester.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class MatchResult:
1818
failed_at: Optional[int] = None
1919
partial_matches: Optional[List[str]] = None
2020

21+
def __str__(self):
22+
return (
23+
f"MatchResult(matches={self.matches}, reason=\"{self.reason}\", "
24+
f"failed_at={self.failed_at}, partial_matches={self.partial_matches})"
25+
)
26+
2127
class RegexTester:
2228
"""
2329
Tests if a string matches a regex pattern and provides detailed feedback.
@@ -92,8 +98,7 @@ def test(self, pattern: str, test_string: str, flags: int = 0) -> MatchResult:
9298
import re as _re
9399
esc = node.value
94100
esc_re = _re.compile(esc)
95-
# Show the escape as written in the pattern (single backslash)
96-
display_esc = esc.encode('utf-8').decode('unicode_escape') if esc.startswith('\\') else esc
101+
display_esc = esc # Always show as written (e.g., '\d')
97102
if esc_re.fullmatch(c):
98103
details.append(f"{c!r} matches escape {display_esc} at position {j}")
99104
i += 1

0 commit comments

Comments
 (0)