Sachin Sachin - 1 year ago 47
Python Question

Deleting all occurances of / after its 2nd occurance in python

I have a URL which is

I want to split string as '', 'about' ,'hello' how to do this ??


There are lots of ways to do this. You could use re.split() to split on a regular expression, for instance.

>>> import re
>>> re.split(r'\b/\b', '')
['', 'about', 'hello']

re is part of the standard library, documented here. The regex itself uses \b which means a boundy between a "word" character and a "non-word" character. You can use regex101 to explore how it works.