簡體   English   中英

有人可以幫我使用以下示例的正則表達式嗎?

[英]Can anyone help me with the regex for the following example?

樣本數據:

"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 PlayerName PlaysOnHomeTeam OptaId .. .. ..

誰能告訴我正則表達式來實現這一目標

您可以使用此:

,?"(\\w+)":

說明:

,? 據說花了0或1 ,

"之前的句子。

(\\w+)是您想要的。 它是單詞a-zA-Z0-9_

"句子后

如果只需要每對的左側字符串:

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']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM