For example I have:
string = 'ST8*010A1~BHT*0019*0 BHT#5*20190114*'
I need to split it by "BHT" only if the character before is "~" and the character after is non-numeric and non-alphabetic and not a space.
I tried this:
new_list = []
new_list = re.split(r'[~]BHT[^A-Za-z0-9 ]', contents)
The issue is that it gives this:
new_list = ['ST8*010A1', '0019*0 BHT#5*20190114*']
I need:
new_list = ['ST8*010A1~', '0019*0 BHT#5*20190114*']
Is there a way to rewrite the code, so it keeps "~"?
Thank you.