Replaces instances of pattern in a string with a replacement. The compiled regex is kept in a cache shared by Match and Search. Args: pattern: regex pattern rep: replacement text s: search string Returns: string with replacements made (or original string if no replacements)
(pattern, rep, s)
| 1052 | |
| 1053 | |
| 1054 | def ReplaceAll(pattern, rep, s): |
| 1055 | """Replaces instances of pattern in a string with a replacement. |
| 1056 | |
| 1057 | The compiled regex is kept in a cache shared by Match and Search. |
| 1058 | |
| 1059 | Args: |
| 1060 | pattern: regex pattern |
| 1061 | rep: replacement text |
| 1062 | s: search string |
| 1063 | |
| 1064 | Returns: |
| 1065 | string with replacements made (or original string if no replacements) |
| 1066 | """ |
| 1067 | if pattern not in _regexp_compile_cache: |
| 1068 | _regexp_compile_cache[pattern] = sre_compile.compile(pattern) |
| 1069 | return _regexp_compile_cache[pattern].sub(rep, s) |
| 1070 | |
| 1071 | |
| 1072 | def Search(pattern, s): |
no outgoing calls
no test coverage detected