Skip to content
Advertisement

Python split a string between different delimiters

I would like to split a string like this

JavaScript

to something like this:

JavaScript

but I can also have this:

JavaScript

to something like this:

JavaScript

The idea at the end is to print it like that

JavaScript

Does someone has an idea ? Thx

Advertisement

Answer

You can take advantage of the fact that re.split retains the “splitter” in the results if it’s a capturing group, and then:

JavaScript

This prints out

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement