def Parser(string):
string = string.split('\n')
import re
for line in string:
line = re.search(r"\S+\t+(\S+\t+)\S+\t+\S+\t+(\S+)\t+\S+", line)
return line.group(1)+line.group(2)
def Parser(string):
string = string.split('\n')
firstline = string.pop(0)
import re
matches = ''
for line in string:
line = re.search(r"\S+\t+(\S+\t+)\S+\t+\S+\t+(\S+)\t+\S+", line)
if line:
match = line.group(1) + line.group(2)+'\n'
matches += match
return matches
答案 0 :(得分:1)
假设您的其他代码(包括正则表达式)是正确的
def Parser(string):
string = string.split('\n')
import re
matches = []
for line in string:
line = re.search(r"\S+\t+(\S+\t+)\S+\t+\S+\t+(\S+)\t+\S+", line)
match = line.group(1) + line.group(2)
matches.extend(match)
return matches
答案 1 :(得分:0)
考虑使用解析器进行输入。 Python附带csv
模块:
import csv
def Parser(string):
output = []
for fields in csv.reader(string.split('\n'), 'excel-tab'):
if len(fields) >= 6:
output.append( fields[1] + '\t' + fields[4] )
return output