I have a configuration file where users can provide regular expressions to match against words, e.g.
wordlist = ["is", r"\b(and)\b"]
The problem is: if a user provides "is"
, this will also match against "This"
-- which is not what I want. The second regex is better since it uses word-boundaries. Unfortunately, this is annoying to do for each word.
My idea is the following: let the user specify raw-strings (which are taken untouched for regex-matching) and "normal strings" (which are first translated to r"\b({})\b".format(word)
for convenience). Is there a way to implement this? Can reflection be used to tell if a string was initially provided as raw-string?
Aucun commentaire:
Enregistrer un commentaire