Aditya Kuls Aditya Kuls -5 years ago 79
Python Question

How to split a statement based on dots ('.'), while excluding dots inside angular brackets(< . >) using regular expressions in python?

I want to split statements by dots using regex in python, while excluding certain dots inside the angular brackets.
Original Statement :

'my name 54. is <not23.> worth mentioning. ok?'

I want to split it into following sentences:

Statement 1 : 'my name 54'
Statement 2 : ' is <not23.> worth mentioning'
Statement 3 : ' ok'

Answer Source

Split on the following regex:


Live demo

import re

str = 'my name 54. is <not23.> worth mentioning. ok?'
regex = re.compile(r"\.(?![^<]*>)")
arr = regex.split(str)

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