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.

3
  • check out the answer here Commented Apr 18, 2020 at 19:53
  • That string looks like its part of a larger serialized data stream. Is it JSON? If so, the answer is to parse the JSON. Urls are difficult to express in a single regex. Commented Apr 18, 2020 at 19:57
  • Maybe regex url":,".*?" Commented Apr 18, 2020 at 22:36

1 Answer 1

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))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.