Yesterday, I needed to add a file path to a regular expression creating a pattern like this:
"some_pattern/%s/more_pattern" % some_path
In the beginning the regular expression did not match, because some_path contained
several regex specific symbols like ? or .. As a quick fix I replaced them with [?]{1} and . with \..
However, I asked myself if there isn't a more reliable or better way to clean a string from regex specific symbols.
- Is such functionality supported in the Python Standard library?
- If not, do you know a regular expression to identify all regex symbols and clean them through a substitute?