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)
| 665 | |
| 666 | |
| 667 | def ReplaceAll(pattern, rep, s): |
| 668 | """Replaces instances of pattern in a string with a replacement. |
| 669 | |
| 670 | The compiled regex is kept in a cache shared by Match and Search. |
| 671 | |
| 672 | Args: |
| 673 | pattern: regex pattern |
| 674 | rep: replacement text |
| 675 | s: search string |
| 676 | |
| 677 | Returns: |
| 678 | string with replacements made (or original string if no replacements) |
| 679 | """ |
| 680 | if pattern not in _regexp_compile_cache: |
| 681 | _regexp_compile_cache[pattern] = sre_compile.compile(pattern) |
| 682 | return _regexp_compile_cache[pattern].sub(rep, s) |
| 683 | |
| 684 | |
| 685 | def Search(pattern, s): |
no test coverage detected
searching dependent graphs…