我有4个元素存储在一个数组中,我只想从提到Approved个关键字的字符串中获取整数.
my_array = ['STK72184 4/28/2022 50 from Exchange Balance, 50 from Earning Balance & 10 from Bonus 25000 Regular 10/20/2023 Approved 4/28/2022',
'STK725721 4/27/2022 50 from Exchange Balance, 40 from Earning Balance & 10 from Bonus Balance 5000 Regular 10/19/2023 Closed 4/27/2022',
'STK725721 4/27/2022 50 from Exchange Balance, 40 from Earning Balance & 10 from Bonus Balance 15000 Regular 10/19/2023 Closed 4/27/2022',
'STK722222 4/26/2022 50 from Exchange Balance, 40 from Earning Balance & 10 from Bonus Balance 10000 Regular 10/18/2023 Approved 4/26/2022']
到目前为止,我只能通过以下操作从列表中获取整数:
import re
# Print integers
nums = [int(re.search(r'\d+000', s)[0]) for s in my_array]
print(nums)
# Printed output:
# [25000, 5000, 15000, 10000]
预期输出为:
[25000,10000]