7

Is there a simple way to transform an exact string matching to a re.compile object ? For example, I would like to mix exact string and regexes.

0

1 Answer 1

11

You can probably use re.escape to escape everything in a string, and then use the escaped string as a pattern.

def transform(s):
    return re.compile(re.escape(s))
Sign up to request clarification or add additional context in comments.

1 Comment

I feel a lot ashamed. So simple... Thanks for this !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.