Use `search` to look for the first occurrence of a regular-expression pattern in a string. A compiled pattern’s `search` method returns `None` when it finds no match. Otherwise, it returns a match object, which is true in a Boolean test and can provide information about the matched text. section 16.1
Check whether a line contains a word
`import re; pattern = re.compile("hello")`. Then `if pattern.search(line):` runs its body only when the line contains `hello`. Compile the pattern once when searching many lines; compilation can significantly speed up large text-processing jobs. section 16.1
import re
regexp = re.compile("hello")
count = 0
file = open("textfile", 'r')
for line in file.readlines():
if regexp.search(line):
count = count + 1
file.close()
print(count)
This listing searches each line of a file and counts matching lines. The Boolean test uses the match object without extracting text from it. section 16.1
Keep the result when you need data from the match: `result = pattern.search(line)`. Check that `result` is not `None` before calling `result.group('phone')` or another named group. A successful overall match does not guarantee text for every group: an optional middle-name group can still return `None`. section 16.4

