Just an if else condition is needed for this case. This will lead to splitting if there is any substring :: present inside the input string, otherwise it will return the actual input string.
>>> def csplit(s): if '::' in s: return [i for i in regex.split(r'(<(?:(?R)|[^<>])*>)|::', s) if i and i != ' '] else: return s >>> csplit('a :: <<a :: b> c>::<a < a < b:: b> :: b> :: b> :: a') ['a ', '<<a :: b> c>', '<a < a < b:: b> :: b> :: b>', ' a'] >>> csplit('a:<a b>') 'a:<a b>' >>> csplit('a< b <c a>>') 'a< b <c a>>'
Avinash raj
source share