#匹配s中的pattern,从头开始匹配 (pattern可用正则)
_regexp_compile_cache = {}
def Match(pattern, s):
if pattern not in _regexp_compile_cache:
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
return _regexp_compile_cache[pattern].match(s)
#查找s中的pattern(pattern可用正则)
def Search(pattern, s):
if pattern not in _regexp_compile_cache:
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
return _regexp_compile_cache[pattern].search(s)
#将s中的pattern替换成rep (pattern,rep可用正则)
def ReplaceAll(pattern, rep, s):
if pattern not in _regexp_compile_cache:
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
return _regexp_compile_cache[pattern].sub(rep, s)