mardi 25 juillet 2017

How to strip random Chars at the end of a String with Regex / Strip() in Python?

What is the preferred way to cut off random characters at the end of a string in Python?

I am trying to simplify a list of URLs to do some analysis and therefore need to cut-off everything that comes after the file extension ".php"

Since the characters that follow after ".php" are different for each URL using strip() doesn't work. I thought about regex and substring(). But what would be the most efficient way to solve this task ?

Example:

Let's say I have the following URLs:

http://ift.tt/2tygFON
http://ift.tt/2uV7n2L

And I want the output to be:

http://ift.tt/1dt4zI4
http://ift.tt/1xn4HWI

Thanks for your advice !




Aucun commentaire:

Enregistrer un commentaire