简体   繁体   中英

Can anyone help me with the regex for the following example?

Sample Data:

"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

what i want is a list with data which is inside the quotes ie PlayerId PlayerName PlaysOnHomeTeam OptaId .. .. ..

Can anyone tell me the regex to achieve this

you can use this:

,?"(\\w+)":

explanation:

,? is said it took 0 or 1 of ,

" before the sentences.

(\\w+) is what u want. It is the word character a-zA-Z0-9_

" after the sentences

example

If you only want the left-hand string for each pair:

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))

Output:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM