Python: Search for regex pattern in string
30 October 2022 (Updated 17 March 2024)
import re
# re.match only searches for match at the beginning
# so this won't return a match
re.match("c", "abcdef")
# re.search will search for match anywhere in the
# string so this will match
re.search("c", "abcdef")
<re.Match object; span=(2, 3), match='c'>
Sources
Tagged:
Python
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment