Aditya Kuls Aditya Kuls - 1 year ago 104
Python Question

How to split a string in python based on dots, ignoring decimal values?

I have the following string:

s = 'This .is sparta 1.2 version. Please check.'

I want to split it based on dots, while ignoring decimal figures.
So, Required Output :

['This ','is sparta 1.2 version','Please check']

I tried following:


The output I am getting is:

['This ', None, 'is sparta 1.2 version', '', ' Please check', None, '']

Why am I getting None and empty strings here? I just want the split strings, ie.

['This ','is sparta 1.2 version','Please check']

Please suggest the rectification here.

Answer Source

Try splitting on


It makes sure the dot isn't preceded, nor followed, by a digit.

See it here at regex101.

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