Home > database >  accessing text from string
accessing text from string

Time:11-03

p=['[Inventor] [Full name] BOLLINGER JOSEPH H [Full name] AHN JANET J [Full name] REILLY PATRICIA A [Full name] MIRIPOL JEFFREY E']

Required output:

BOLLINGER JOSEPH H,AHN JANET J, REILLY PATRICIA A , MIRIPOL JEFFREY E

CodePudding user response:

This is one of the approach using python regex:

data = "[Inventor] [Full name] BOLLINGER JOSEPH H [Full name] AHN JANET J [Full name] REILLY PATRICIA A [Full name] MIRIPOL JEFFREY E"
import re
# Replace [Inventor] and [Full name] with ,
names = re.sub('\[Full name\]|\[Inventor\]', ',', data)
# Now split on ',' and get the non-empty values added in 'names'
names = [name.strip() for name in names.split(',') if name.strip()]
print (names)

Output:

['BOLLINGER JOSEPH H', 'AHN JANET J', 'REILLY PATRICIA A', 'MIRIPOL JEFFREY E']
  • Related