1

I am trying to further split an already split string to further clean it up and remove unnecessary bits of info. This is a URL split by '/'

['https:', '', 'expressjs.com', 'en', 'starter', 'hello-world.html']

I would like to be able to make it:

['https:', '', 'expressjs','com', 'en', 'starter', 'hello-world','html']

Any thoughts?

2 Answers 2

4

re.split can split a string on every match for your regex

>>> re.split('[/\.]', 'https://expressjs.com/en/starter/hello-world.html')
['https:', '', 'expressjs', 'com', 'en', 'starter', 'hello-world', 'html']

[/\.] matches any forward-slash or period character

Sign up to request clarification or add additional context in comments.

1 Comment

The backslash is not required when the . is inside [].
1

Try this:

L = ['https:', '', 'expressjs.com', 'en', 'starter', 'hello-world.html']
L =  [subitem for item in L for subitem in item.split('.')]

print(L)

Output:

['https:', '', 'expressjs', 'com', 'en', 'starter', 'hello-world', 'html']

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.