8 Python Regex Match Vs Search Functions
8 Python Regex Match Vs Search Functions
`search` functions
match
search
Note that match checks for a match only at the beginning of a string, while
search checks for a match anywhere in the string!
Example 1 #
Let’s try to find the word Python :
#!/usr/bin/python
import re
if m:
print "m.group() : ", m.group()
else:
print "No match by obj.search!!"
else:
print "No match by obj.match"
You will be able to see that, match function won’t find the word “Python”, but
search can! Also note the use of the re.I (case insensitive) option.
Example 2: #
#!/usr/bin/python
import re
if m:
print "email address : ", email[:m.start()] + email[m.end():]
else:
print "No match!!"