+1 vote
in Class 11 by kratos

Study the given script

defmetasearch( ):

import re

p=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

1 Answer

+1 vote
by kratos
 
Best 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

...