January 2019
Beginner
318 pages
8h 23m
English
The search() function of the re module will search through a string. It will look for any location for the specified re pattern. The search() will take a pattern and text and it will search through our specified string for a match. It will return a match object when a match is found. It will return None if no match found. The match object has two methods:
The syntax for this function is as follows:
re.search(pattern, string)
Create a re_search.py script and write following content in it:
import repattern = ['programming', 'hello']str_line = 'Python programming is fun'for p in pattern: print("Searching for %s in %s" % (p, str_line)) ...Read now
Unlock full access