例如:
import re pattern = r "\b(cat)\b" match = re.search(pattern, "The cat sat!" ) if match: print ( "Match 1" ) match = re.search(pattern, "We s>cat<tered?" ) if = " " match:=" " print=" " (" match = " " 2" ) = " " match=" re.search(pattern, " " we = " " scattered." ) = " " 3" ) = " " <=" " pre=" "> <p class = "resu" ><b>结果:<b>< / b>< / b>< / p><b><b> <pre class = "brush:python" > >>> Match 1 Match 2 >>> < / pre> <div class = "tip" > "\b(cat)\b" 基本匹配单词“CAT”包围的单词边界。 < / div> < / b>< / b>< / tered?")> |