Regexp not performing the same in FTP versus Python
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Fri Feb 9 01:51:02 EST 2007
In <1170978596.337428.261110 at h3g2000cwc.googlegroups.com>, IamIan wrote:
> Hello all,
>
> I'm trying to use a regular expression in an FTP script to list
> certain files. When run in a standard FTP session the command:
>
> dir ????????.??[oOdDnNmM]*
>
> returns 48 files. When I use the following Python script it prints
> roughly 12 files (a subset of the 48), ending with 'None':
>
> […]
>
> Is my Python syntax off?
Your `re` syntax is off. What you give FTP is a shell or glob pattern,
not a regular expression for the `re` module.
The `fnmatch` module has a function to translate a glob pattern to a `re`
pattern:
In [8]: fnmatch.translate('????????.??[oOdDnNmM]*')
Out[8]: '........\\...[oOdDnNmM].*$'
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list