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)
| 1037 | |
| 1038 | |
| 1039 | def ReplaceAll(pattern, rep, s): |
| 1040 | """Replaces instances of pattern in a string with a replacement. |
| 1041 | |
| 1042 | The compiled regex is kept in a cache shared by Match and Search. |
| 1043 | |
| 1044 | Args: |
| 1045 | pattern: regex pattern |
| 1046 | rep: replacement text |
| 1047 | s: search string |
| 1048 | |
| 1049 | Returns: |
| 1050 | string with replacements made (or original string if no replacements) |
| 1051 | """ |
| 1052 | if pattern not in _regexp_compile_cache: |
| 1053 | _regexp_compile_cache[pattern] = sre_compile.compile(pattern) |
| 1054 | return _regexp_compile_cache[pattern].sub(rep, s) |
| 1055 | |
| 1056 | |
| 1057 | def Search(pattern, s): |
no outgoing calls
no test coverage detected