Incompatible with re if single { in the pattern

Create issue
Issue #206 resolved
animalize created an issue
>>> p = r"g_img={url:'([^']+)'"

# compiled successfully in re
>>> re.compile(p)
re.compile("g_img={url:'([^']+)'")

# failed in regex
>>> regex.compile(p)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python35\lib\site-packages\regex.py", line 345, in compile
    return _compile(pattern, flags, kwargs)
  File "C:\Python35\lib\site-packages\regex.py", line 501, in _compile
    caught_exception.pos)
_regex_core.error: bad fuzzy constraint at position 8

Test on 2016.05.13

Comments (5)

  1. Matthew Barnett repo owner

    This is a tricky one because it's difficult to tell whether what comes after the "{" is a bad fuzzy constraint or a literal.

    For example, if you wrote r"x{e", is that all a literal (r"x\{e") or is it an error ("missing }")?

    How about r"(?:cats|cat){e<=1"? Trailing literal or "missing }"?

    How far should it go before deciding that it's meant to be a fuzzy constraint?

  2. animalize reporter

    At least change this prompt:

    \_regex\_core.error: bad fuzzy constraint at position 8
    

    A bit strange for someone who is not using fuzzy matching, remove the word fuzzy or something else.

  3. animalize reporter

    2016.05.23 has a very small issue.

    Single { is fine for normal repeat quantifier, but not fuzzy quantifier. A bit inconsistent.

    >>> regex.compile(r"g_img={3")
    regex.Regex('g_img={3', flags=regex.V0)
    
    >>> regex.compile(r"g_img={e")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Python35\lib\site-packages\regex.py", line 345, in compile
        return _compile(pattern, flags, kwargs)
      File "C:\Python35\lib\site-packages\regex.py", line 501, in _compile
        caught_exception.pos)
    _regex_core.error: expected } at position 8
    
  4. Log in to comment