|
|
发表于 2016-3-2 22:26:27
|
显示全部楼层
不知道是否满足
- root@iZ25uz51fd7Z:/home/VVFock3r# cat test.py
- import re
-
- def split2(str2, fs):
- l = re.findall(r'(.*?' + fs + ')', str2, re.S)
- if not str2.endswith(fs):
- l.append(str2.split(fs)[-1])
- return l
复制代码
执行结果:
- In [1]: from test import split2
- In [2]: str1 = '!Hello!World!'
- In [3]: split2(str1, '!')
- Out[3]: ['!', 'Hello!', 'World!']
- In [4]:
- In [4]: str2 = '\ndef!Hello!World!\nabc'
- In [5]:
- In [5]: split2(str2, '!')
- Out[5]: ['\ndef!', 'Hello!', 'World!', '\nabc']
- In [6]:
复制代码 |
|