实际的业务中有这样一个场景:
TXT中的数据是这样的,
1,2,3,4,,"11,22,33","111,222"
需求:需要处理成去掉双引号的
1,2,3,4,,11-22-33,111-222
实际中,每行的数据哪一列是带 “ ” 的也不确定,双引号中包含几个 ,也是不确定的
解决方案:
import re
def split_wordname():
name = ' 1,2,3,4,,"11,22,33","111,222" '
r = ""
for t in re.split(r'("[^"]*")',name):
if t[0] == '"':
t = t.replace(",", "-")[1:-1]
r += t
print(r)