如何删除文件中的垃圾字符数据如下所示

2024-05-29 04:45:30 发布

您现在位置:Python中文网/ 问答频道 /正文

[15;1Runts/Jumbos[16;1Errors Rx/Tx[17;1Total Rx Pkts[18;1Tx Pkts[19;1rx MBs[20;1Tx MBs[21;1ARP/ICMP Pkts[23;1Pattern Type[24;1Tx Count/%Rate[25;1PktSize/Tx Burst[26;1Src/Dest Port]


Tags: rateporttypecountrxdesticmptx
1条回答
网友
1楼 · 发布于 2024-05-29 04:45:30

你可以用regex替换。你知道吗

import re
string = '[15;1Runts/Jumbos [16;1Errors Rx/Tx [17;1Total Rx Pkts [18;1 Tx Pkts [19;1 Rx MBs [20;1 Tx MBs [21;1ARP/ICMP Pkts [23;1Pattern Type [24;1Tx Count/% Rate [25;1PktSize/Tx Burst [26;1Src/Dest Port'
print(re.sub('\[\d{1,2}\;\d','',string))
>>> 'Runts/Jumbos Errors Rx/Tx Total Rx Pkts  Tx Pkts  Rx MBs  Tx MBs ARP/ICMP Pkts Pattern Type Tx Count/% Rate PktSize/Tx Burst Src/Dest Port'

相关问题 更多 >

    热门问题