I have a JSON like this in a list agents_json:
[
{
'name': 'ip-10-13-28-114 (5)',
'active': True
},
{
'name': 'ip-10-13-28-127 (6)',
'active': True
},
{
'name': 'ip-10-13-28-127',
'active': True
}
]
I want to delete the objects from the json where the value of the name matches my variable from a list: agents_to_remove it contains strings like the name value of the third object.
So Problem is my list doesn't contain the number between brackets and a lot of objects have names like that.
Can you tell me if its possible to match the json value with a regex in here:
for i in range(len(agents_json)):
for j in agents_to_remove:
regex = re.search(j*)
if agents_json[i]["name"] == j* :
agents_json.pop(i)
break
Obviosly j* isn't working, and after a few hours of searching I still don't have any idea how I could accomplish this.
str.startswith: docs.python.org/3/library/stdtypes.html#str.startswith