This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年02月21日 02:55 by py.user, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg153836 - (view) | Author: py.user (py.user) * | Date: 2012年02月21日 02:55 | |
>>> import re
>>> re.search(r'(?<=(a|b))(\w+)', 'abc').groups()
('a', 'bc')
>>> re.search(r'(?<=(^))(\w+)', 'abc').groups()
('', 'abc')
>>> re.search(r'(?<=(^|$))(\w+)', 'abc').groups()
('', 'abc')
>>> re.search(r'(?<=($|^))(\w+)', 'abc').groups()
('', 'abc')
>>> re.search(r'(?<=(^|a))(\w+)', 'abc').groups()
Traceback (most recent call last):
File "/usr/local/lib/python3.2/functools.py", line 176, in wrapper
result = cache[key]
KeyError: (<class 'str'>, '(?<=(^|a))(\\w+)', 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.2/re.py", line 158, in search
return _compile(pattern, flags).search(string)
File "/usr/local/lib/python3.2/re.py", line 255, in _compile
return _compile_typed(type(pattern), pattern, flags)
File "/usr/local/lib/python3.2/functools.py", line 180, in wrapper
result = user_function(*args, **kwds)
File "/usr/local/lib/python3.2/re.py", line 267, in _compile_typed
return sre_compile.compile(pattern, flags)
File "/usr/local/lib/python3.2/sre_compile.py", line 495, in compile
code = _code(p, flags)
File "/usr/local/lib/python3.2/sre_compile.py", line 480, in _code
_compile(code, p.data, flags)
File "/usr/local/lib/python3.2/sre_compile.py", line 115, in _compile
raise error("look-behind requires fixed-width pattern")
sre_constants.error: look-behind requires fixed-width pattern
>>>
|
|||
| msg222129 - (view) | Author: Mark Lawrence (BreamoreBoy) * | Date: 2014年07月02日 21:25 | |
@py.user please accept our apologies for having missed this. @Ezio can you comment on this please. |
|||
| msg222199 - (view) | Author: Ezio Melotti (ezio.melotti) * (Python committer) | Date: 2014年07月03日 16:47 | |
I believe this is not a bug. As the error says a look-behind requires the pattern to have a fixed length. In re.search(r'(?<=(a|b))(\w+)', 'abc').groups() the two possible patterns in the look behind are "a" and "b", both with length 1. In re.search(r'(?<=(^|$))(\w+)', 'abc').groups() the two possible patterns in the look behind are "^" and "$", both with length 0. In re.search(r'(?<=(^|a))(\w+)', 'abc').groups() the two possible patterns in the look behind are "^" and "a", one with length 0 and the other with length 1. This is not allowed and raises an error. Similarly, in re.search(r'(?<=(ab|a))(\w+)', 'abc').groups() the two patterns have length 2 and 1, and the same error is raised. Closing as not a bug. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:26 | admin | set | github: 58277 |
| 2014年07月03日 16:47:35 | ezio.melotti | set | status: open -> closed resolution: not a bug messages: + msg222199 stage: resolved |
| 2014年07月02日 21:25:27 | BreamoreBoy | set | nosy:
+ BreamoreBoy messages: + msg222129 |
| 2012年02月21日 02:55:58 | py.user | create | |