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)
| 523 | |
| 524 | |
| 525 | def ReplaceAll(pattern, rep, s): |
| 526 | """Replaces instances of pattern in a string with a replacement. |
| 527 | |
| 528 | The compiled regex is kept in a cache shared by Match and Search. |
| 529 | |
| 530 | Args: |
| 531 | pattern: regex pattern |
| 532 | rep: replacement text |
| 533 | s: search string |
| 534 | |
| 535 | Returns: |
| 536 | string with replacements made (or original string if no replacements) |
| 537 | """ |
| 538 | if pattern not in _regexp_compile_cache: |
| 539 | _regexp_compile_cache[pattern] = sre_compile.compile(pattern) |
| 540 | return _regexp_compile_cache[pattern].sub(rep, s) |
| 541 | |
| 542 | |
| 543 | def Search(pattern, s): |
no outgoing calls
no test coverage detected