简体   繁体   中英

Python regular expression for retrieving value that is wrapped in quotes

I would like to create a python regular expression that will search through unparsed data that is returned from a webhook:

{"Opportunity":{"Client Name":"Mike DevTest","Client Email":"sample@gmail.com","Primary Contact":"Mike DevTest","Event Start Date/Time": "12/24/2021 4:00 AM","Event End Time":"6:30 PM","Event Location":"Houston","Event Type":"Wedding","State": "TX","Venue": "Virtual Chicago","Additional Musicians": "false","Cocktail Music": "true","Dinner Music": "true","Grand Piano Shells": "false","uplights": "false","mini piano shells": "false","projector": "false","Wedding Ceremony": "false","Evening Entertainment": "true","DJ Services": "true","Type Of Ensemble": "Dueling Pianos","Primary Owner Email":"sample@gmail.com","Primary Owner Mobile":"(555) 555-555","Salesforce Id":"0068F000002G5quQAC","Added To PIP":"true","Date added to PIP":"3/1/2022","Amount":"1700.00","Performers":"2","Lead Photographer":"true","2nd Photographer":"true","Lead Videographer":"false","2nd Videographer":"false","Client Time Zone":"MT","Studio Time Zone":"ET","Studio Start Time":"12:30 AM","Studio End Time":"1:30 AM","Inbound or Generated":"Generated","Piano Man":"true","Rocket Man":"true","Great Balls of Fire":"true","Main Service Interested In":"Photo"}}

From the data above, I want it to return the value for the “ Salesforce Id ”, which would be 0068F000002G5quQAC

Can someone help me with that regular expression?

You can simply access the value by accessing the respective dict keys:

>>> d = {"Opportunity":{"Client Name" :"Mike DevTest","Client Email":"sample@gmail.com","Primary Contact":"Mike DevTest","Event Start Date/Time" : "12/24/2021 4:00 AM","Event End Time":"6:30 PM","Event Location":"Houston","Event Type":"Wedding","State" : "TX","Venue" : "Virtual Chicago","Additional Musicians" : "false","Cocktail Music" : "true","Dinner Music" : "true","Grand Piano Shells" : "false","uplights" : "false","mini piano shells" : "false","projector" : "false","Wedding Ceremony" : "false","Evening Entertainment" : "true","DJ Services" : "true","Type Of Ensemble" : "Dueling Pianos","Primary Owner Email":"sample@gmail.com","Primary Owner Mobile":"(555) 555-555","Salesforce Id":"0068F000002G5quQAC","Added To PIP":"true","Date added to PIP":"3/1/2022","Amount":"1700.00","Performers":"2","Lead Photographer":"true","2nd Photographer":"true","Lead Videographer":"false","2nd Videographer":"false","Client Time Zone":"MT","Studio Time Zone":"ET","Studio Start Time":"12:30 AM","Studio End Time":"1:30 AM","Inbound or Generated":"Generated","Piano Man":"true","Rocket Man":"true","Great Balls of Fire":"true","Main Service Interested In":"Photo"}}
>>> d['Opportunity']['Salesforce Id']
'0068F000002G5quQAC'

If this is a string, you can load it using the json module before:

>>> s = '{"Opportunity":{"Client Name" :"Mike DevTest","Client Email":"sample@gmail.com","Primary Contact":"Mike DevTest","Event Start Date/Time" : "12/24/2021 4:00 AM","Event End Time":"6:30 PM","Event Location":"Houston","Event Type":"Wedding","State" : "TX","Venue" : "Virtual Chicago","Additional Musicians" : "false","Cocktail Music" : "true","Dinner Music" : "true","Grand Piano Shells" : "false","uplights" : "false","mini piano shells" : "false","projector" : "false","Wedding Ceremony" : "false","Evening Entertainment" : "true","DJ Services" : "true","Type Of Ensemble" : "Dueling Pianos","Primary Owner Email":"sample@gmail.com","Primary Owner Mobile":"(555) 555-555","Salesforce Id":"0068F000002G5quQAC","Added To PIP":"true","Date added to PIP":"3/1/2022","Amount":"1700.00","Performers":"2","Lead Photographer":"true","2nd Photographer":"true","Lead Videographer":"false","2nd Videographer":"false","Client Time Zone":"MT","Studio Time Zone":"ET","Studio Start Time":"12:30 AM","Studio End Time":"1:30 AM","Inbound or Generated":"Generated","Piano Man":"true","Rocket Man":"true","Great Balls of Fire":"true","Main Service Interested In":"Photo"}}'
>>> from json import loads
>>> d = loads(s)
>>> 

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