Я знаю, что ОП просит ответ на регулярное выражение.Но я не очень хорошо знаю регулярные выражения.Вот еще одно решение, чтобы помочь (так как ответа не было дано в течение последних 5 дней).
my_str = 'Permanent Address : Fata colony | warsaw | road | Party : PTI'
final_list = []
items = my_str.split(':')
for i, sep in enumerate(items):
if i == 0:
# only adds key to the list (in first iteration)
next_key = sep
final_list.append(next_key)
elif i == len(items) - 1:
''' Checks if it is the last split(:) element ('PTI' in this case) and appends everything to the last item in final_list'''
split2 = sep.split('|')
prev_val = ''.join(split2)
final_list[i-1] += ': ' + prev_val
else:
''' Excluding last item (from split(|)), appends everything else to the previous item of final_list'''
split2 = sep.split('|')
prev_val = ''.join(split2[:-1])
final_list[i-1] += ': ' + prev_val
next_key = split2[-1]
final_list.append(next_key)
print(final_list)
Надеюсь, это поможет