import re
ori_list = re.split("=#=",ori_str)
# you can imagine your goal is to find the string wrapped between signs of "=#="
# so after the split, the even number position must be the parts outsides of "=#="
# and the odd number position is what you want
for i in range(len(ori_list)):
if i%2 == 1:#odd position
print(ori_list[i])
s = '321@5=85@45@41=#=I-LOVE-STACK-OVER-FLOW=#=3234@41@=q#$^1=@=xx$q=@=xpa$=4319=#=|I-ALSO-LOVE-SO=#=3123123'
parts = s.split('=#=')
print(''.join([parts[i] for i in range(1,len(parts),2)]))
解释在代码中。你知道吗
除了@DirtyBit的答案外,如果您还想处理2'=#='以上的情况,可以拆分字符串,然后添加其他元素:
输出
使用
split()
:使用
regex
:输出:
相关问题 更多 >
编程相关推荐