0
import re
see = """https://www.flipkart.com/honor-7c-blue-64-gb/p/itmfaybh5jjzhmpz?pid=MOBF3T87CECXMZQH&lid=LSTMOBF3T87CECXMZQHFPGOZQ&marketplace=FLIPKART","name":"Honor 7C (Blue, 64 GB)"},{"@type":"ListItem","position":2,"url":"https://www.flipkart.com/honor-7c-blue-32-gb/p/itmf53qmmggh2ynj?pid=MOBF3T87QFSQXGCM&lid=LSTMOBF3T87QFSQXGCMUHVDHM&marketplace=FLIPKART","name":"Honor 7C (Blue, 32 GB)"},{"@type":"ListItem","position":3,"url":"https://www.flipkart.com/honor-7c-black-32-gb/p/itmf5ch2zb97avvz?pid=MOBF3T877EEKFWGN&lid=LSTMOBF3T877EEKFWGN9WQ3A4&marketplace=FLIPKART","name":"Honor 7C (Black, 32 GB)"},{"@type":"ListItem","position":4,"url":"https://www.flipkart.com/honor-8c-black-64-gb/p/itmfc8c4fsekrpdp?pid=MOBFC8C8FXXNHZ7C&lid=LSTMOBFC8C8FXXNHZ7CZYQGKP&marketplace=FLIPKART"""
regex = r'\"position":2,\"url\":\",\"name\":\"(.*)\"'
match = re.findall(regex, see)

print(match)

I want to capture just the names from the above variable the output must be in this way - (Honor 7C (Blue, 64 GB),Honor 7C (Blue, 32 GB),Honor 7C (Black, 32 GB),)

while i run the above code it just gives me empty parenthesis

I think so that something is wrong with my regex so anyone please help me

THANKING IN ADVANCE.

1 Answer 1

1

Do you mean this? This will look for the "name" and take everything within the next quotes as the name regex group.

(.*?) means everything until the first occurrence of ".

import re

see = """https://www.flipkart.com/honor-7c-blue-64-gb/p/itmfaybh5jjzhmpz?pid=MOBF3T87CECXMZQH&lid=LSTMOBF3T87CECXMZQHFPGOZQ&marketplace=FLIPKART","name":"Honor 7C (Blue, 64 GB)"},{"@type":"ListItem","position":2,"url":"https://www.flipkart.com/honor-7c-blue-32-gb/p/itmf53qmmggh2ynj?pid=MOBF3T87QFSQXGCM&lid=LSTMOBF3T87QFSQXGCMUHVDHM&marketplace=FLIPKART","name":"Honor 7C (Blue, 32 GB)"},{"@type":"ListItem","position":3,"url":"https://www.flipkart.com/honor-7c-black-32-gb/p/itmf5ch2zb97avvz?pid=MOBF3T877EEKFWGN&lid=LSTMOBF3T877EEKFWGN9WQ3A4&marketplace=FLIPKART","name":"Honor 7C (Black, 32 GB)"},{"@type":"ListItem","position":4,"url":"https://www.flipkart.com/honor-8c-black-64-gb/p/itmfc8c4fsekrpdp?pid=MOBFC8C8FXXNHZ7C&lid=LSTMOBFC8C8FXXNHZ7CZYQGKP&marketplace=FLIPKART"""
regex = r'\"name\":\"(?P<name>.*?)\"'
print(re.findall(regex, see))
# ['Honor 7C (Blue, 64 GB)', 'Honor 7C (Blue, 32 GB)', 'Honor 7C (Black, 32 GB)']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.