background :
In the process of using Python, you are certainly distressed about the use of escaped characters, because sometimes we need to use some special symbols such as "$ *". ^ "The original intention, sometimes need to be escaped after the function, and the escape character is cumbersome to use, error-prone, then save you are not re.escape."
Escape (Pattern)
Escape all non-alphanumeric characters in pattern.
Defined:
Re.escape (pattern) can be applied to all characters in a string that may be interpreted as a regular operator. You can use this function if the string is long and contains many special techniques, and you do not want to enter a large number of backslashes, or if the string is from the user (for example, by using the Raw_input function to get input), and is used as part of the regular expression.
To illustrate:
- 1
> re.escape(‘www.python.org‘)
- 2
‘www\\.python\\.org‘
- 3
- 4
>re.findall(re.escape(‘w.py‘),"jw.pyji w.py.f")
- 5
[‘w.py‘, ‘w.py‘]
Here Re.escape (' w.py ') serves as the regular expression part of the function Re.findall function.
Python Regular expression re (ii) escape