以下示例可以帮助我使用正则表达式吗?

时间:2018-05-04 05:25:33

标签: python regex split

示例数据:

"PlayerId":169193,"PlayerName":"Alexandre Lacazette","PlaysOnHomeTeam":true,"OptaId":"p59966","GoalsConcededInBox":1,"ShotsInsideBox":8,"ShotsWoodwork":1,"TotalPasses":31,"PassSuccess":23,"KeyPasses":5,"DribblesAttempted":3,"DribblesWon":2,"AerialsWon":5,"AerialsLost":2,"TacklesSuccess":3,"TacklesAttempted":3

我想要的是一个包含在引号内的数据的列表,即 PlayerId 选手姓名 PlaysOnHomeTeam OptaId .. .. ..

任何人都可以告诉我正则表达式实现这个

2 个答案:

答案 0 :(得分:3)

你可以用这个:

,?"(\w+)":

说明:

据说

,?占用了,

中的0或1 在句子之前

"

(\w+)就是你想要的。这是单词a-zA-Z0-9_

句子后

"

example

答案 1 :(得分:0)

如果您只想要每对的左手字符串:

import json
s = '{'+ '''"PlayerId":169193,"PlayerName":"Alexandre Lacazette","PlaysOnHomeTeam":true,"OptaId":"p59966","GoalsConcededInBox":1,"ShotsInsideBox":8,"ShotsWoodwork":1,"TotalPasses":31,"PassSuccess":23,"KeyPasses":5,"DribblesAttempted":3,"DribblesWon":2,"AerialsWon":5,"AerialsLost":2,"TacklesSuccess":3,"TacklesAttempted":3''' + '}'
list(json.loads(s))

输出:

['PlayerId', 'PlayerName', 'PlaysOnHomeTeam', 'OptaId', 'GoalsConcededInBox', 'ShotsInsideBox', 'ShotsWoodwork', 'TotalPasses', 'PassSuccess', 'KeyPasses', 'DribblesAttempted', 'DribblesWon', 'AerialsWon', 'AerialsLost', 'TacklesSuccess', 'TacklesAttempted']