import re
def rearrange_name(name):
result= re.search(r'^([\w.]*),([\w.]*)$', name)
return '{} {}'.format(result[2], result[1])
print(result=rearrange_name('Lovely Ada'))
CodePudding user response:
The space separating the groups is not being captured by your regex pattern
import re
def rearrange_name(name):
result= re.search(r'^(\w*)[ ,](\w*)$', name)
return '{} {}'.format(result[2], result[1])
print(rearrange_name('Lovely Ada'))