Every line of 'python regex replace' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
40 def regex_replace(value, pattern, replacement, ignorecase=False, multiline=False): 41 """Do a regex search and replace on 'value'""" 42 flags = 0 43 if ignorecase: 44 flags |= re.I 45 if multiline: 46 flags |= re.M 47 compiled_pattern = re.compile(pattern, flags=flags) 48 return compiled_pattern.sub(replacement, str(value))
222 def convert_python_source(source, rex=re.compile(r"[uU]('.*?')")): 223 # type: (unicode, Pattern) -> unicode 224 # remove Unicode literal prefixes 225 if PY3: 226 return rex.sub('\\1', source) 227 else: 228 return source
194 def replace(string, old, new): 195 return string.replace(old, new)
195 def RegexEscape(str): 196 return str.replace('\\', '\\\\')
231 def _compile(self, use_regex, flags): 232 super(Replacement, self)._compile(use_regex, flags) 233 precompile_exceptions(self.exceptions, use_regex, flags)
28 def replace(self, text): 29 # 过滤特殊字符 30 s = re.sub(r"[^a-zA-Z\d',.!?$:-]+", r" ", text) 31 # 拆分缩写 32 for (pattern, repl) in self.patterns: 33 s = re.sub(pattern, repl, s) 34 # 拆分标点 35 text = [] 36 for fragment in s.split(): 37 text.extend(re.split(self._WORD_SPLIT, fragment)) 38 return ' '.join(text)