作者:风云时尚_榜中榜_434 | 来源:互联网 | 2023-05-19 16:02
Imcurrentlybuildingatoolthatwillhavetomatchfilenamesagainstapattern.Forconvenience,
I'm currently building a tool that will have to match filenames against a pattern. For convenience, I intend to provide both lazy matching (in a glob-like fashion) and regexp matching. For example, the following two snippets would eventually have the same effects:
我目前正在构建一个工具,它必须将文件名与模式匹配。为了方便起见,我打算提供两个延迟匹配(在全局样式中)和regexp匹配。例如,以下两个片段最终会产生相同的效果:
@mylib.rule('static/*.html')
def myfunc():
pass
@mylib.rule(r'^static/([^/]+)\.html')
def myfunc():
pass
AFAIK r''
is only useful to the Python parser and it actually creates a standard str
instance after parsing (the only difference being that it keeps the \
).
AFAIK r“只对Python解析器有用,它实际上在解析后创建了一个标准的str实例(惟一的区别是它保留了\)。
Is anybody aware of a way to tell one from another?
有没有人知道一种区分彼此的方法?
I would hate to have to provide two alternate decorators for the same purpose or, worse, resorting manually parsing the string to determine if it's a regexp or not.
我不希望为相同的目的提供两个替代decorator,或者更糟糕的是,通过手工解析字符串来确定它是否是regexp。
3 个解决方案