Am 18.09.2019 um 22:22 schrieb Chris Angelico:
On Thu, Sep 19, 2019 at 6:20 AM Ralf M. <ral...@t-online.de> wrote:
Am 17.09.2019 um 20:59 schrieb Manfred Lotz:
I have a function like follows
def regex_from_filepat(fpat):
rfpat = fpat.replace('.', '\\.') \
.replace('%', '.') \
.replace('*', '.*')
return '^' + rfpat + '$'
As I don't want to have the replace() functions in one line my
question is if it is ok to spread the statement over various lines as
shown above, or if there is a better way?
Thanks.
Not related to your question, but:
You seem to try to convert a Windows wildcard pattern to a regex
pattern. However, wildcards sometimes behave a bit different than what
you assume. I know for instance that *.* matches any filename, even if
the filename doesn't contain a dot.
Hmm, why do you assume it's a Windows wildcard pattern specifically?
ChrisA
I think I jumped to that conclusion because the example didn't treat [ ]
as special characters. [ ] are special in a unix shell, but not at a cmd
prompt. Thinking it over, [ ] would need a much differnt treatment and
might be left out of the example for that reason, though.
Also I may be biased: I mostly use Windows, Linux only occasionally.
Ralf M.
--
https://mail.python.org/mailman/listinfo/python-list