0
import re   
string = """position":1,"url":"https://www.flipkart.com/honor-8c-black-64-gb/p/itmfc8c4fsekrpdp?pid=MOBFC8C8FXXNHZ7C&lid=LSTMOBFC8C8FXXNHZ7CZYQGKP&marketplace=FLIPKART,"""
regex = "\w\w\w\w\w\w\w\w\W\W\d\W\W\w\w\w\W\W\W\w\w\w\w\w\W\/\/(...)\"\W"             
match = re.findall(regex, string)  
print(match)

I want to capture just the link from the above variable the output must be in this way -(https://www.flipkart.com/honor-8c-black-64-gb/p/itmfc8c4fsekrpdp?pid=MOBFC8C8FXXNHZ7C&lid=LSTMOBFC8C8FXXNHZ7CZYQGKP&marketplace=FLIPKART) 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.

tdelaney
  • 73,364
  • 6
  • 83
  • 116
Jobin 07
  • 21
  • 4

1 Answers1

1

You have some formatting issues. Here you go (assuming this format is consistent, otherwise follow the advice from the comments):

import re

string ='"position":1,"url":"https://www.flipkart.com/honor-8c-black-64-gb/p/itmfc8c4fsekrpdp?pid=MOBFC8C8FXXNHZ7C&lid=LSTMOBFC8C8FXXNHZ7CZYQGKP&marketplace=FLIPKART"'
regex = r'\"url\":\"(.*)\"'
match = re.search(regex, string)

print(match.group(1))
Grajdeanu Alex
  • 388
  • 6
  • 20