如何在Python3中匹配字符和空格后的字符串?



我有以下字符串:

'- Submission GMV / return finance027110/06 Abdul Rahman -26,00- Submission GMV / return finance02432548/08 Michael Scott -56,47- GMV success. 452630/10/21 Lehazq998890/92 +60,00'

如何返回值:

[['- Submission PVT / return finance027110/06 Abdul Rahman','-26,00'],
['- Submission LTD / return finance02432548/08 Michael Scott','-56,47'],
['- GMV success. 452630/10/21 Lehazq998890/92', '+60,00']]

我循环到多个输入。因此,每次迭代的输出行数不同。但分割模式保持不变。

您的需求很容易通过使用re.findall和两个捕获组来实现:

inp = "- Submission GMV / return finance027110/06 Abdul Rahman -26,00- Submission GMV / return finance02432548/08 Michael Scott -56,47- GMV success. 452630/10/21 Lehazq998890/92 +60,00"
matches = re.findall(r'(-.*?) ([+-]d+(?:,d+)?)', inp)
print(matches)

这个打印:

[('- Submission GMV / return finance027110/06 Abdul Rahman', '-26,00'),
('- Submission GMV / return finance02432548/08 Michael Scott', '-56,47'),
('- GMV success. 452630/10/21 Lehazq998890/92', '+60,00')]

尝试这样做data.split('- ')[1:]

相关内容

  • 没有找到相关文章

最新更新