I'll provide an example to see what I mean:
my_string1='005010X221A1~ST*835*0001~BPR*I*642.65*C*'
my_string2='005010X221A1~ST*835*0001~BPRI*642.65*C*'
I want to know when "BPR" has special characters from both sides, by special characters I mean everything that is not a letter or digit.
I tried the following, but it doesn't work because it returns False for both strings, and I need True for string1:
res=False
if re.search(r'(BPR(?<=/D)|BPR(?<=/W))&(BPR(?=\D)|BPR(?=\W))',my_string1) != None:
res=True
I never used 're' before, so if I'm using it wrong, please correct me, or if there is a better way to do it. Thanks, everyone!