Plan Savings Budget 20000 Account Personal Dividend Minimum Amount abcd123 Plan Current Budget 1000 Account Joint Dividend Maximum Amount abcd123
这里我要提取的内容是储蓄,20000,个人和最低金额。
Plan (.*?) Budget (.*?) Account (.*?) Dividend (.*?)
这没有给我最低金额。
Expected output: [['Savings', '20000', 'Personal', 'Minimum Amount'],['Current','1000','Joint','Maximum Amount']
答案 0 :(得分:0)
我将创建一个“拆分”字符串数组并循环并执行您的正则表达式:
input = "Plan Savings Budget 20000 Account Personal Dividend Minimum Amount abcd123 Plan Current Budget 1000 Account Joint Dividend Maximum Amount abcd123"
theList = input.split("abcd123")
for item in theList:
# Do your regex processing here
答案 1 :(得分:0)
考虑如下使用re.findall
;
re.findall('(Savings|Current| \d+ |Personal|Joint|Maximum Amount|Minimum Amount)', y, re.I)
y
是您要搜索该模式的字符串。
这是我得到的结果。
>>> ['Savings',' 20000 ','Personal','Minimum Amount','Current',' 1000 ','Joint','Maximum Amount']