0
Help
How to move the initials after surname beforehand in the string Authors: Komeili A. Cali H. Beveridge T. J. and Newman D. K.???
3 Answers
0
need more information to help you. so you wanna change the string from "Authors: Komeili A. Cali H. Beveridge T. J. and Newman D. K." into what?
0
Into "Authors: A. Komeili H. Cali T. Beveridge..
0
Try this in Python :)
#Authors: Komeili A. Cali H. Beveridge T. J. and Newman D. K.
import re
authors = 'Authors: Komeili A. Cali H. Beveridge T. J. and Newman D. K.'
pattern = r"(\w+)\s+((\w+\.(\s)*)+)"
matchs = re.findall(pattern, authors)
if matchs:
firstmatch = re.search(pattern, authors).start()
result = authors[:firstmatch]
print(firstmatch)
for match in matchs:
result += '{givenname} {surname} '.format(surname=match[0].strip(), givenname = match[1].strip())
print(result)