'Python RegEx finding all matches between certain strings
this is my first question!
I have a certain string looking like this (cutout):
"""
"random": [
{
"d3rdda": "dasd212dsadsa",
"author": {
"email": "[email protected]",
"name": "John Doe"
},
"""
I need to find all authors with the corresponding email adresses, so I want to get every match that starts with
"author": {
and ends with
}
because that would exactly give me
["email": "[email protected]", "name": "John Doe"]
Sadly, this is not working:
result = re.findall(r'\"author\": {.+}$', ext)
print(result)
I'm very grateful for any support!
Solution 1:[1]
This seems to work for this example, but every other line would have to have the same format
re.findall(r'\"author\".*\S+\s+.*\S+\s+.*\S+\s+}', ext)
Solution 2:[2]
You may try this.
re.findall('"author": {.+}', ext, re.DOTALL)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kirsten_J |
| Solution 2 | Shiping |
