Python保留分隔符的Split

Python牛逼小技巧,Python保留分隔符的Split方法。

Python牛逼小技巧,Python保留分隔符的Split方法。其实在Python手册里面写了很清楚,因为原来用不着,所以没注意,但是这次因为处理文本的时候,需要保留标点符号,因此特地的去查了一下。

>>>re.split('(W)', 'foo/bar spamneggs')
['foo', '/', 'bar', ' ', 'spam', 'n', 'eggs']

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.