تابع search()(The search() Function)
عملکرد search()
رشته را جستجو می کند
برای یک مطابقت، و یک مطابقت شی را در صورت وجود
مطابقت.
اگر بیش از یک مسابقه وجود داشته باشد،
فقط اولین مورد مسابقه برگردانده می شود:
مثال
Search for the first white-space character in the string:
import re
txt = "The rain in Spain"
x = re.search("s",
txt)
print("The first white-space character is located in
position:", x.start())
اگر هیچ منطبقی یافت نشد، مقدار هیچ
برگردانده می شود:
مثال
Make a search that returns no match:
import re
txt = "The rain in Spain"
x = re.search("Portugal",
txt)
print(x)