fork download
  1. import re
  2. strings = ['ABC WS YMQ234.03WS TOY234.03USD468.06END','FUR BB LAB Q10.00 199.00USD209.00END','YAS DG TYY Q AWSMSN11.32 2503.08LD VET Q JKLOLE11.32 2503.08USD5028.80END','PPP VP LAP Q10.00 M342.41EE SFD Q10.00 282.24USD644.65END']
  3. rx = r'(\bQ\s?[A-Z]*)?(?<!\d)(\d+\.\d{2})(?=.*\d\.\d{2}END)'
  4. for s in strings:
  5. matches = [x.group(2) for x in re.finditer(rx, s) if not x.group(1)] # note the if condition that drops unwlecome matches
  6. print(s, matches, sep=" => ")
Success #stdin #stdout 0.02s 9468KB
stdin
Standard input is empty
stdout
ABC WS YMQ234.03WS TOY234.03USD468.06END => ['234.03', '234.03']
FUR BB LAB Q10.00 199.00USD209.00END => ['199.00']
YAS DG TYY Q AWSMSN11.32 2503.08LD VET Q JKLOLE11.32 2503.08USD5028.80END => ['2503.08', '2503.08']
PPP VP LAP Q10.00 M342.41EE SFD Q10.00 282.24USD644.65END => ['342.41', '282.24']