diff --git a/elementpath/regex/patterns.py b/elementpath/regex/patterns.py index d4fbe00..f9177f9 100644 --- a/elementpath/regex/patterns.py +++ b/elementpath/regex/patterns.py @@ -122,7 +122,7 @@ def parse_character_class() -> CharacterClass: while pos < pattern_len: ch = pattern[pos] if ch == '.': - regex.append(ch if dot_all else '[^\r\n]') + regex.append(ch if dot_all else r'[^\r\n]') elif ch in ('^', '$'): if not anchors: regex.append(r'\%s' % ch) diff --git a/tests/test_regex.py b/tests/test_regex.py index c9a5773..b8e0646 100644 --- a/tests/test_regex.py +++ b/tests/test_regex.py @@ -626,7 +626,7 @@ def test_issue_079(self): def test_dot_wildcard(self): regex = translate_pattern('.+', anchors=False) - self.assertEqual(regex, '^([^\r\n]+)$(?!\\n\\Z)') + self.assertEqual(regex, '^([^\\r\\n]+)$(?!\\n\\Z)') pattern = re.compile(regex) self.assertIsNone(pattern.search('line1\rline2\r')) self.assertIsNone(pattern.search('line1\nline2')) @@ -635,7 +635,7 @@ def test_dot_wildcard(self): self.assertEqual(pattern.search('abc').group(0), 'abc') regex = translate_pattern('.+T.+(Z|[+-].+)', anchors=False) - self.assertEqual(regex, '^([^\r\n]+T[^\r\n]+(Z|[\\+\\-][^\r\n]+))$(?!\\n\\Z)') + self.assertEqual(regex, '^([^\\r\\n]+T[^\\r\\n]+(Z|[\\+\\-][^\\r\\n]+))$(?!\\n\\Z)') pattern = re.compile(regex) self.assertEqual(pattern.search('12T0A3+36').group(0), '12T0A3+36') self.assertEqual(pattern.search('12T0A3Z').group(0), '12T0A3Z') @@ -903,7 +903,7 @@ def test_anchors(self): def test_lazy_quantifiers(self): regex = translate_pattern('.*?') - self.assertEqual(regex, '[^\r\n]*?') + self.assertEqual(regex, '[^\\r\\n]*?') regex = translate_pattern('[a-z]{2,3}?') self.assertEqual(regex, '[a-z]{2,3}?') regex = translate_pattern('[a-z]*?')