How to escape all special characters for regex in Python?

PythonServer Side ProgrammingProgramming

We use re.escape() to escape the special characters −

The following code shows how all special characters in given string are escaped using re.escape() method

>>> p = '5*(67).89?'
>>> re.escape(p)
'5\\*\\(67\\)\\.89\\?'
raja
Published on 11-Jan-2018 11:47:12
Advertisements