SyntaxStudy
Sign Up
Python re.match vs re.search
Python Beginner 3 min read

re.match vs re.search

match vs search

re.match() checks at the start of the string only. re.search() scans the entire string for the first match.

Example
import re

text = "Hello World"
print(re.match(r"World", text))   # None (not at start)
print(re.search(r"World", text))  # match object
Pro Tip

Use re.search() when you do not know where in the string the match occurs.