fork download
  1. import re
  2. texts=['XX=BB|3|3|1|1|PLP|KLWE|9999|9999', 'XX=BB|3|3|1|1|2|PLP|KPOK|99999|99999', '999|999|999|9999|999']
  3. pattern = r'(BB(?:\|\d){4,6}\|[^\s|]{3}\|[^\s|]{4}\|)9{2,9}\|9{2,9}(?!\d)'
  4. repl = r'\g<1>12|21'
  5. for text in texts:
  6. print( re.sub(pattern, repl, text) )
Success #stdin #stdout 0.03s 9612KB
stdin
Standard input is empty
stdout
XX=BB|3|3|1|1|PLP|KLWE|12|21
XX=BB|3|3|1|1|2|PLP|KPOK|12|21
999|999|999|9999|999