[New-bugs-announce] [issue25734] fnmatch regular expression can be improved
Alberto Galera
report at bugs.python.org
Wed Nov 25 09:43:46 EST 2015
New submission from Alberto Galera:
# https://hg.python.org/cpython/file/tip/Lib/fnmatch.py
fnmatch reviewing the code I've noticed that the outcome of the regular expression all returns generated in the first result
l97:
res = res + '.*'
to:
res = res + '.*?'
l100:
return res + '\Z(?ms)'
to:
return res + '$(?ms)'
example test:
import re
import fnmatch
urls = ['example/l1/l2/test3-1.py',
'example/l1/test2-1.py',
'example/l1/test2-2.py',
'example/l1/l2/l3/test4-1.py']
regex = fnmatch.translate('example/*')
# 'example\\/.*\\Z(?ms)'
re.findall(regex, "\n".join(urls))
# return ['example/l1/l2/test3-1.py\nexample/l1/test2-1.py\nexample/l1/test2-2.py\nexample/l1/l2/l3/test4-1.py']
# suggested change
re.findall('example\\/.*?$(?ms)', "\n".join(urls))
# return ['example/l1/l2/test3-1.py',
# 'example/l1/test2-1.py',
# 'example/l1/test2-2.py',
# 'example/l1/l2/l3/test4-1.py']
----------
components: Library (Lib)
messages: 255361
nosy: Alberto Galera
priority: normal
severity: normal
status: open
title: fnmatch regular expression can be improved
type: behavior
versions: Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25734>
_______________________________________
More information about the New-bugs-announce
mailing list