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:
@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 \
).
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.