Regex – How to find all value with a specific key from json format in Python

I want to find all the link for the large keyword from the following string "large": "https://m.media-amazon.com/images/I/41mHHkM79UL._AC_.jpg" I have looked some other posts and on some other websites too but none of my attempts seem to work.

The whole string is like this:

"""
P.when('A').register("ImageBlockATF", function(A){
var data = {
'colorImages': { 'initial': [
{
"hiRes": "https://m.media-amazon.com/images/I/81zzDnLOXmL._AC_SL1500_.jpg",
"thumb": "https://m.media-amazon.com/images/I/41mHHkM79UL._AC_US40_.jpg",
"large": "https://m.media-amazon.com/images/I/41mHHkM79UL._AC_.jpg",
"main": {
"https://m.media-amazon.com/images/I/81zzDnLOXmL._AC_SY355_.jpg": [
355,
355
],
"https://m.media-amazon.com/images/I/81zzDnLOXmL._AC_SY450_.jpg": [
450,
450
],
"https://m.media-amazon.com/images/I/81zzDnLOXmL._AC_SX425_.jpg": [
425,
425
],
"https://m.media-amazon.com/images/I/81zzDnLOXmL._AC_SX466_.jpg": [
466,
466
],
"https://m.media-amazon.com/images/I/81zzDnLOXmL._AC_SX522_.jpg": [
522,
522
],
"https://m.media-amazon.com/images/I/81zzDnLOXmL._AC_SX569_.jpg": [
569,
569
],
"https://m.media-amazon.com/images/I/81zzDnLOXmL._AC_SX679_.jpg": [
679,
679
]
},
"variant": "MAIN",
"lowRes": null,
"shoppableScene": null
},
{
"hiRes": "https://m.media-amazon.com/images/I/91EX6CXAetL._AC_SL1500_.jpg",
"thumb": "https://m.media-amazon.com/images/I/51Xf2DrAufL._AC_US40_.jpg",
"large": "https://m.media-amazon.com/images/I/51Xf2DrAufL._AC_.jpg",
"main": {
"https://m.media-amazon.com/images/I/91EX6CXAetL._AC_SY355_.jpg": [
355,
355
],
"https://m.media-amazon.com/images/I/91EX6CXAetL._AC_SY450_.jpg": [
450,
450
],
"https://m.media-amazon.com/images/I/91EX6CXAetL._AC_SX425_.jpg": [
425,
425
],
"https://m.media-amazon.com/images/I/91EX6CXAetL._AC_SX466_.jpg": [
466,
466
],
"https://m.media-amazon.com/images/I/91EX6CXAetL._AC_SX522_.jpg": [
522,
522
],
"https://m.media-amazon.com/images/I/91EX6CXAetL._AC_SX569_.jpg": [
569,
569
],
"https://m.media-amazon.com/images/I/91EX6CXAetL._AC_SX679_.jpg": [
679,
679
]
},
"variant": "PT01",
"lowRes": null,
"shoppableScene": null
},
{
"hiRes": "https://m.media-amazon.com/images/I/91HB5N1ArxL._AC_SL1500_.jpg",
"thumb": "https://m.media-amazon.com/images/I/517s1wNq+BL._AC_US40_.jpg",
"large": "https://m.media-amazon.com/images/I/517s1wNq+BL._AC_.jpg",
"main": {
"https://m.media-amazon.com/images/I/91HB5N1ArxL._AC_SY355_.jpg": [
355,
355
],
"https://m.media-amazon.com/images/I/91HB5N1ArxL._AC_SY450_.jpg": [
450,
450
],
"https://m.media-amazon.com/images/I/91HB5N1ArxL._AC_SX425_.jpg": [
425,
425
],
"https://m.media-amazon.com/images/I/91HB5N1ArxL._AC_SX466_.jpg": [
466,
466
],
"https://m.media-amazon.com/images/I/91HB5N1ArxL._AC_SX522_.jpg": [
522,
522
],
"https://m.media-amazon.com/images/I/91HB5N1ArxL._AC_SX569_.jpg": [
569,
569
],
"https://m.media-amazon.com/images/I/91HB5N1ArxL._AC_SX679_.jpg": [
679,
679
]
},
"variant": "PT02",
"lowRes": null,
"shoppableScene": null
},
{
"hiRes": "https://m.media-amazon.com/images/I/81u4gn4By+L._AC_SL1500_.jpg",
"thumb": "https://m.media-amazon.com/images/I/417qX3hFhSL._AC_US40_.jpg",
"large": "https://m.media-amazon.com/images/I/417qX3hFhSL._AC_.jpg",
"main": {
"https://m.media-amazon.com/images/I/81u4gn4By+L._AC_SY355_.jpg": [
355,
355
],
"https://m.media-amazon.com/images/I/81u4gn4By+L._AC_SY450_.jpg": [
450,
450
],
"https://m.media-amazon.com/images/I/81u4gn4By+L._AC_SX425_.jpg": [
425,
425
],
"https://m.media-amazon.com/images/I/81u4gn4By+L._AC_SX466_.jpg": [
466,
466
],
"https://m.media-amazon.com/images/I/81u4gn4By+L._AC_SX522_.jpg": [
522,
522
],
"https://m.media-amazon.com/images/I/81u4gn4By+L._AC_SX569_.jpg": [
569,
569
],
"https://m.media-amazon.com/images/I/81u4gn4By+L._AC_SX679_.jpg": [
679,
679
]
},
"variant": "PT03",
"lowRes": null,
"shoppableScene": null
},
{
"hiRes": "https://m.media-amazon.com/images/I/8144z2T8HVL._AC_SL1500_.jpg",
"thumb": "https://m.media-amazon.com/images/I/410iFp5eaDL._AC_US40_.jpg",
"large": "https://m.media-amazon.com/images/I/410iFp5eaDL._AC_.jpg",
"main": {
"https://m.media-amazon.com/images/I/8144z2T8HVL._AC_SY355_.jpg": [
355,
355
],
"https://m.media-amazon.com/images/I/8144z2T8HVL._AC_SY450_.jpg": [
450,
450
],
"https://m.media-amazon.com/images/I/8144z2T8HVL._AC_SX425_.jpg": [
425,
425
],
"https://m.media-amazon.com/images/I/8144z2T8HVL._AC_SX466_.jpg": [
466,
466
],
"https://m.media-amazon.com/images/I/8144z2T8HVL._AC_SX522_.jpg": [
522,
522
],
"https://m.media-amazon.com/images/I/8144z2T8HVL._AC_SX569_.jpg": [
569,
569
],
"https://m.media-amazon.com/images/I/8144z2T8HVL._AC_SX679_.jpg": [
679,
679
]
},
"variant": "PT04",
"lowRes": null,
"shoppableScene": null
},
{
"hiRes": "https://m.media-amazon.com/images/I/710ixzIU0qL._AC_SL1500_.jpg",
"thumb": "https://m.media-amazon.com/images/I/41CfvwfIbzL._AC_US40_.jpg",
"large": "https://m.media-amazon.com/images/I/41CfvwfIbzL._AC_.jpg",
"main": {
"https://m.media-amazon.com/images/I/710ixzIU0qL._AC_SY355_.jpg": [
355,
355
],
"https://m.media-amazon.com/images/I/710ixzIU0qL._AC_SY450_.jpg": [
450,
450
],
"https://m.media-amazon.com/images/I/710ixzIU0qL._AC_SX425_.jpg": [
425,
425
],
"https://m.media-amazon.com/images/I/710ixzIU0qL._AC_SX466_.jpg": [
466,
466
],
"https://m.media-amazon.com/images/I/710ixzIU0qL._AC_SX522_.jpg": [
522,
522
],
"https://m.media-amazon.com/images/I/710ixzIU0qL._AC_SX569_.jpg": [
569,
569
],
"https://m.media-amazon.com/images/I/710ixzIU0qL._AC_SX679_.jpg": [
679,
679
]
},
"variant": "PT05",
"lowRes": null,
"shoppableScene": null
},
{
"hiRes": "https://m.media-amazon.com/images/I/91JLoX-b-vL._AC_SL1500_.jpg",
"thumb": "https://m.media-amazon.com/images/I/5164gjcgHIL._AC_US40_.jpg",
"large": "https://m.media-amazon.com/images/I/5164gjcgHIL._AC_.jpg",
"main": {
"https://m.media-amazon.com/images/I/91JLoX-b-vL._AC_SY355_.jpg": [
355,
355
],
"https://m.media-amazon.com/images/I/91JLoX-b-vL._AC_SY450_.jpg": [
450,
450
],
"https://m.media-amazon.com/images/I/91JLoX-b-vL._AC_SX425_.jpg": [
425,
425
],
"https://m.media-amazon.com/images/I/91JLoX-b-vL._AC_SX466_.jpg": [
466,
466
],
"https://m.media-amazon.com/images/I/91JLoX-b-vL._AC_SX522_.jpg": [
522,
522
],
"https://m.media-amazon.com/images/I/91JLoX-b-vL._AC_SX569_.jpg": [
569,
569
],
"https://m.media-amazon.com/images/I/91JLoX-b-vL._AC_SX679_.jpg": [
679,
679
]
},
"variant": "PT06",
"lowRes": null,
"shoppableScene": null
},
{
"hiRes": "https://m.media-amazon.com/images/I/91W7gb7CjWL._AC_SL1500_.jpg",
"thumb": "https://m.media-amazon.com/images/I/61VgpB5DRyL._AC_US40_.jpg",
"large": "https://m.media-amazon.com/images/I/61VgpB5DRyL._AC_.jpg",
"main": {
"https://m.media-amazon.com/images/I/91W7gb7CjWL._AC_SY355_.jpg": [
355,
355
],
"https://m.media-amazon.com/images/I/91W7gb7CjWL._AC_SY450_.jpg": [
450,
450
],
"https://m.media-amazon.com/images/I/91W7gb7CjWL._AC_SX425_.jpg": [
425,
425
],
"https://m.media-amazon.com/images/I/91W7gb7CjWL._AC_SX466_.jpg": [
466,
466
],
"https://m.media-amazon.com/images/I/91W7gb7CjWL._AC_SX522_.jpg": [
522,
522
],
"https://m.media-amazon.com/images/I/91W7gb7CjWL._AC_SX569_.jpg": [
569,
569
],
"https://m.media-amazon.com/images/I/91W7gb7CjWL._AC_SX679_.jpg": [
679,
679
]
},
"variant": "PT07",
"lowRes": null,
"shoppableScene": null
}
]
},
'colorToAsin': {'initial': {}
},
'holderRatio': 1.0,
'holderMaxHeight': 700,
'heroImage': {'initial': []
},
'heroVideo': {'initial': []
},
'spin360ColorData': {'initial': {}
},
'spin360ColorEnabled': {'initial': 0
},
'spin360ConfigEnabled': true,
'spin360LazyLoadEnabled': false,
'showroomEnabled': false,
'showroomViewModel': {'initial': {}
},
'playVideoInImmersiveView': true,
'useTabbedImmersiveView': true,
'totalVideoCount':'0',
'videoIngressATFSlateThumbURL':'',
'mediaTypeCount':'0',
'atfEnhancedHoverOverlay' : true,
'winningAsin': 'B0033990ZQ',
'weblabs' : {},
'aibExp3Layout' : 1,
'aibRuleName' : 'frank-powered',
'acEnabled' : true,
'dp60VideoPosition': 0,
'dp60VariantList': '',
'dp60VideoThumb': '',
'dp60MainImage': 'https: //m.media-amazon.com/images/I/81zzDnLOXmL._AC_SY355_.jpg',
'imageBlockRenderingStartTime': Date.now(),
'shoppableSceneWeblabEnabled': false,
'airyConfig' :A.$.parseJSON('{
"jsUrl": "https://images-na.ssl-images-amazon.com/images/G/01/vap/video/airy2/prod/2.0.1460.0/js/airy.skin._CB485981857_.js",
"cssUrl": "https://images-na.ssl-images-amazon.com/images/G/01/vap/video/airy2/prod/2.0.1460.0/css/beacon._CB485971591_.css",
"swfUrl": "https://images-na.ssl-images-amazon.com/images/G/01/vap/video/airy2/prod/2.0.1460.0/flash/AiryBasicRenderer._CB485925577_.swf",
"foresterMetadataParams": {
"marketplaceId": "ATVPDKIKX0DER",
"method": "Sports.ImageBlock",
"requestId": "CNWR29DQN7HDJNZBH41R",
"session": "142-4118660-8915941",
"client": "Dpx"
}
}')
};
A.trigger('P.AboveTheFold'); // trigger ATF event.
return data;
});
"""

is it possible with regex? I am using python. Thanks in advance

Answer

You can use this pattern: (?<="large":s")[^"]+

This code will give you all links with key "large":

import re
pattern = r"(?<="large":s")[^"]+"
text = """
Your huge string
"""
print(re.findall(pattern, text))

Explanation:

  • (?<=) Starting matches from where that pattern inside it is in behind position.
  • "large":s" Match exactly with "large": "
  • [^"]+ Match one or more anything except for double quotation.