Sachin Sachin - 2 years ago 81
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 ??

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download