0

string:

ecsdcsdcsdfvdfv":"https://scdsscdcsdent-mxp1-1.cdninstdscsdcagdssdcsdam.com/v/t51.283485-19/s320x320/79000872_1455436197941341_7513464347075543040_n.pnk?_nc_ht=scontent-mxp1-1.cdninadcdcdm.codcsdcm&_nc_ohc=0fehqjedb48AX8r72Hi&oh=eb1f6a78a2dcd67e443aa7f74eee91b4&oe=5E7F0A0C","vsvdfvsfvcfvfdcvfd

substring that i want to get:

https://scdsscdcsdent-mxp1-1.cdninstdscsdcagdssdcsdam.com/v/t51.283485-19/s320x320/79000872_1455436197941341_7513464347075543040_n.pnk?_nc_ht=scontent-mxp1-1.cdninadcdcdm.codcsdcm&_nc_ohc=0fehqjedb48AX8r72Hi&oh=eb1f6a78a2dcd67e443aa7f74eee91b4&oe=5E7F0A0C

i tried this but doesn't work

print (log.split("ecsdcsdcsdfvdfv",1)[1]) 
3
  • 2
    Why not just parse it as json and take the value? Commented Dec 20, 2019 at 12:52
  • @Guimoute i tried your split, it doesn't work Commented Dec 20, 2019 at 13:03
  • @Sayse if you find a simple solution using json.parse i'll follow it Commented Dec 20, 2019 at 13:05

3 Answers 3

2

This yield the expected result.

The way you used .split() was wrong, you did not include the " character.

string = 'ecsdcsdcsdfvdfv":"https://scdsscdcsdent-mxp1-1.cdninstdscsdcagdssdcsdam.com/v/t51.283485-19/s320x320/79000872_1455436197941341_7513464347075543040_n.pnk?_nc_ht=scontent-mxp1-1.cdninadcdcdm.codcsdcm&_nc_ohc=0fehqjedb48AX8r72Hi&oh=eb1f6a78a2dcd67e443aa7f74eee91b4&oe=5E7F0A0C","vsvdfvsfvcfvfdcvfd'
substring = string.split('ecsdcsdcsdfvdfv":"')[1].split('","vsvdfvsfvcfvfdcvfd')[0]
Sign up to request clarification or add additional context in comments.

2 Comments

This is what i was looking for! Thanks
you forgot a " on the start
2

You can try this

log.split('":"')[1].split('","')[0]

But this is not the best way to do what you are trying to achieve. Better parse it and get what you want.

7 Comments

That won't give the expected output though
I know :) Edited
I don't like this solution because i i got a string with more ":" it doesn't work
More ":"? What do you mean? :D
int the start and in the end of the string more ":"
|
1

If you want to get the string between the ":" and ",", then you can use regular expression to do it.

re.match('(.*\":\")([^\",\"]*)(\",\".*)', log).group(2)

Given your input

'ecsdcsdcsdfvdfv":"https://scdsscdcsdent-mxp1-1.cdninstdscsdcagdssdcsdam.com/v/t51.283485-19/s320x320/79000872_1455436197941341_7513464347075543040_n.pnk?_nc_ht=scontent-mxp1-1.cdninadcdcdm.codcsdcm&_nc_ohc=0fehqjedb48AX8r72Hi&oh=eb1f6a78a2dcd67e443aa7f74eee91b4&oe=5E7F0A0C","vsvdfvsfvcfvfdcvfd'

you will get

'https://scdsscdcsdent-mxp1-1.cdninstdscsdcagdssdcsdam.com/v/t51.283485-19/s320x320/79000872_1455436197941341_7513464347075543040_n.pnk?_nc_ht=scontent-mxp1-1.cdninadcdcdm.codcsdcm&_nc_ohc=0fehqjedb48AX8r72Hi&oh=eb1f6a78a2dcd67e443aa7f74eee91b4&oe=5E7F0A0C'

And if you input something like

'ecsdcsdcs":"dfvdfv":"https://s...F0A0C","vsvdfvsfvcfvfdc","vfd'

you will get

'https://s...F0A0C'

Dont forget to import re.

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.