全句匹配:

1
2
3
import re

is_match = re.match(r"[regex_str]*", "match_str")

部分匹配:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import re

matchObj = re.search(r"[regex_str]*", "match_str")

if matchObj:
    print("matchObj.group() : {}".format(matchObj.group()))
    print("matchObj.group(1) : {}".format(matchObj.group(1)))
    print("matchObj.group(2) : {}".format(matchObj.group(2)))
else:
    print("No match!!")

正则替换:

1
2
3
import re

replace_result = re.sub(r"[regex_str]*", "replace_to", "match_str")