Python: Regex re.search
re.search(regex, text)
-
Return MatchObject if regex matches (part or whole of a string), else return
None
. re.search(regex, text, flags=flags)
- Use Regex Flags
# python 3 # example of re.search() import re mObj = re.search(r"\w+@\w+\.com", "from xyz@example.com address") if mObj: print("yes") print(mObj.group()) # xyz@example.com else: print("no")