One particular quirk of the (otherwise quite powerful) re
module in Python is that re.split()
will never split a string on a zero-length match, for example if I want to split a string along word boundaries:
>>> re.split(r"s+|", "Split along words, preserve punctuation!")
['Split', 'along', 'words,', 'preserve', 'punctuation!']
instead of
['', 'Split', 'along', 'words', ',', 'preserve', 'punctuation', '!']
Why does it have this limitation? Is it by design? Do other regex flavors behave like this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…