Returns the string with control characters for Pattern syntax escaped. For example: "hello!" => "hello\!".
(string)
| 895 | return compile(pattern, *args, **kwargs).search(sentence) |
| 896 | |
| 897 | def escape(string): |
| 898 | """ Returns the string with control characters for Pattern syntax escaped. |
| 899 | For example: "hello!" => "hello\!". |
| 900 | """ |
| 901 | for ch in ("{","}","[","]","(",")","_","|","!","*","+","^"): |
| 902 | string = string.replace(ch, "\\"+ch) |
| 903 | return string |
| 904 | |
| 905 | #--- PATTERN MATCH --------------------------------------------------------------------------------- |
| 906 |