1.

Study the given script defmetasearch( ): import rep=re.compile(‘sing+’) searchl=re.search(p,’ Some singers sing well’)if searchl: match=searchl.group( ) index=searchl.start( ) lindex=search 1 ,end( )print “matched”, match, “at index”, index ,”ending at”, lindex else:print “No match found”metasearch( )What will be the output of the above script if search( ) from the re module is replaced by match ( ) of the re module. Justify your answer

Answer»

The output would be “N match found” 

Justification : re.search( ) rill attempt the pattern throughout the string, i ntil it finds a match. re.match( ) on the other hand, only attempts the pattern at the very start of the string.

Example :

>>>re.match(“d”, “abcdef’) # No match >>>re.search(“d”, “abcdef’) # Match



Discussion

No Comment Found