Message152590
The doc chapters are entitled "fnmatch — Unix filename pattern matching" and "glob — Unix style pathname pattern expansion". The first explicitly disclaims the feature you request: "Be aware there is no way to quote meta-characters.", suggests using re for anything beyond fnmatch, and shows to use .translate to make a start in doing so. For your example:
>>> re.match(r".*\[Ver\.2\].*", "Document[Ver.2].doc")
<_sre.SRE_Match object at 0x000000000331AF38>
Indeed, fnmatch works by using translate() and re.match. What you are asking for in something in between the unix language and re. If one re feature is added, why not another?
So the scope of these modules is clearly circumscribed. I suspect their intent was to make it easy to translate unix shell scripts into Python.
What you are asking for in something in between. If you want to pursue this, post on python-list or python-ideas to garner more support. But I anticipate rejection as not needed and contrary to intent.
Not obvious from the doc is that an unmatch '[' or ']' is escaped:
>>> name = "Document[Ver.2.doc"
>>> pattern = "*[Ver.2*"
>>> fnmatch.fnmatch(name, pattern)
True
>>> name = "DocumentVer.2].doc"
>>> pattern = "*Ver.2]*"
>>> fnmatch.fnmatch(name, pattern)
True
I presume this matches the *nix behavior, but don't know. |
|
Date |
User |
Action |
Args |
2012-02-04 04:41:12 | terry.reedy | set | recipients:
+ terry.reedy, fruch |
2012-02-04 04:41:12 | terry.reedy | set | messageid: <1328330472.06.0.296320613225.issue13929@psf.upfronthosting.co.za> |
2012-02-04 04:41:11 | terry.reedy | link | issue13929 messages |
2012-02-04 04:41:10 | terry.reedy | create | |
|