I have the following strings:
"LP, bar, company LLP, foo, LLP"
"LLP, bar, company LLP, foo, LP"
"LLP,bar, company LLP, foo,LP" # note the absence of a space after/before comma to be removed
I am looking for a regex that takes those inputs and returns the following:
"LP bar, company LLP, foo LLP"
"LLP bar, company LLP, foo LP"
"LLP bar, company LLP, foo LP"
What I have so fat is this:
import re
def fix_broken_entity_names(name):
"""
LLP, NAME -> LLP NAME
NAME, LP -> NAME LP
"""
pattern_end = r'^(LL?P),'
pattern_beg_1 = r', (LL?P)$'
pattern_beg_2 = r',(LL?P)$'
combined = r'|'.join((pattern_beg_1, pattern_beg_2, pattern_end))
return re.sub(combined, r' \1', name)
When I run it tho:
>>> fix_broken_entity_names("LP, bar, company LLP, foo,LP")
Out[1]: ' bar, company LLP, foo '
I'd be very thankful for any tips or solutions :)