regex=ur"" #正则表达式 if re.search(regex, subject): do_something() else: do_anotherthing() |
regex=ur"\Z" #正则表达式末尾以\Z结束 if re.match(regex, subject): do_something() else: do_anotherthing() |
regex=ur"" #正则表达式 match = re.search(regex, subject) if match: # match start: match.start() # match end (exclusive): atch.end() # matched text: match.group() do_something() else: do_anotherthing() |
regex=ur"" #正则表达式 match = re.search(regex, subject) if match: result = match.group() else: result = "" |
regex=ur"" #正则表达式 match = re.search(regex, subject) if match: result = match.group(1) else: result = "" |
regex=ur"" #正则表达式 match = re.search(regex, subject) if match: result = match.group"groupname") else: result = "" |
result = re.findall(regex, subject) |
for match in re.finditer(r"<(.*?)\s*.*?/\1>", subject) # match start: match.start() # match end (exclusive): atch.end() # matched text: match.group() |
reobj = re.compile(regex) |
reobj = re.compile(regex) if reobj.search(subject): do_something() else: do_anotherthing() |
reobj = re.compile(r"\Z") #正则表达式末尾以\Z 结束 if reobj.match(subject): do_something() else: do_anotherthing() |
reobj = re.compile(regex) match = reobj.search(subject) if match: # match start: match.start() # match end (exclusive): atch.end() # matched text: match.group() do_something() else: do_anotherthing() |
reobj = re.compile(regex) match = reobj.search(subject) if match: result = match.group() else: result = "" |
reobj = re.compile(regex) match = reobj.search(subject) if match: result = match.group(1) else: result = "" |
reobj = re.compile(regex) match = reobj.search(subject) if match: result = match.group("groupname") else: result = "" |
reobj = re.compile(regex) result = reobj.findall(subject) |
reobj = re.compile(regex) for match in reobj.finditer(subject): # match start: match.start() # match end (exclusive): match.end() # matched text: match.group() |
#用newstring替换subject中所有与正则表达式regex匹配的子串 result = re.sub(regex, newstring, subject) |
reobj = re.compile(regex) result = reobj.sub(newstring, subject) |
result = re.split(regex, subject) |