Dec-05-2021, 10:19 PM
(This post was last modified: Dec-06-2021, 05:12 AM by Larz60+.
Edit Reason: fixed code tags
)
I want to replace either the matched key's value or the value matched with strings of the same length but consisting of
There is no problem with Email. Email is fine but i could not figure out how to do the regex for "Name": "Jack", "Name":"Bethany"
This is my regular- expressions pattern:
`Email: [email protected]
Email: [email protected]`
How to write regex for Name: Jack and Name: Bethany, any help would be appreciated.
[/python]
*
only.There is no problem with Email. Email is fine but i could not figure out how to do the regex for "Name": "Jack", "Name":"Bethany"
This is my regular- expressions pattern:
regex_pattern = r'[\w\.\-]+@[\w\.\-]+'
import json import re jsonString =[{ "Name": "Jack", "Email": "[email protected]" }, { "Name": "Bethany", "Email": "[email protected]" } ] regex_pattern = r'[\w\.\-]+@[\w\.\-]+' def database(jsonString, regex_pattern): s1 = json.dumps(jsonString) jsonObject = json.loads(s1) print(jsonObject) for key in range(len(jsonObject)): value = jsonObject[key] print("The key and value are ({}) = ({})".format(key, value)) matchReg = re.findall(regex_pattern, str(jsonObject)) print("matchReg: " ,matchReg) for mail in matchReg: print("Email: ", mail) database(jsonString, regex_pattern)This is result for email:
`Email: [email protected]
Email: [email protected]`
How to write regex for Name: Jack and Name: Bethany, any help would be appreciated.
[/python]