{???Y???ST7352915,01,KEY:,SB48679,Land, ,FGNR_17,LBV11DU09PSB48679,DMcode,F7SB48679, 13.07.23 20:19:51.026 Output: Node 19112, 89 bytes ==> 19112 ???g???ST8638618,01,KEY:,SB48679,MOTNR,5478F982,E_Code,B48B20C ,Brand,BBA ,DMCode,HNSB48679, 13.07.23 20:19:51.021 Output: Node 19112, 103 bytes ==> 19112 ???????ST8738756,01,KEY:,SB48679,Color,416,Fgnr_17,LBV11DU09PSB48679,V_Type,BMW6475JS ,E_code,B48B20C ,Built,2023-07,MNP,135,Gg1kg,2510,E_Displ,1998,Seat,5,Towing,-- ,DMCode,7VSB48679, 13.07.23 20:19:51.016 Output: Node 19112, 197 bytes ==> 19112} 用正则表达式去除 Fgnr_17,后面的值和DMcode,后面的值
时间: 2023-09-30 21:09:50 浏览: 148
SSH如何实现本地远程端口转发
要去除 Fgnr_17 后面的值和 DMcode 后面的值,您可以使用正则表达式 `FGNR_17,([^,]+),DMcode,([^,]+)` 来匹配并替换这些内容为空字符串。以下是一个示例代码:
```python
import re
data = """
{???Y???ST7352915,01,KEY:,SB48679,Land, ,FGNR_17,LBV11DU09PSB48679,DMcode,F7SB48679,
13.07.23 20:19:51.026 Output: Node 19112, 89 bytes ==> 19112
???g???ST8638618,01,KEY:,SB48679,MOTNR,5478F982,E_Code,B48B20C ,Brand,BBA ,DMCode,HNSB48679,
13.07.23 20:19:51.021 Output: Node 19112, 103 bytes ==> 19112
???????ST8738756,01,KEY:,SB48679,Color,416,Fgnr_17,LBV11DU09PSB48679,V_Type,BMW6475JS ,E_code,B48B20C ,Built,2023-07,MNP,135,Gg1kg,2510,E_Displ,1998,Seat,5,Towing,-- ,DMCode,7VSB48679,
13.07.23 20:19:51.016 Output: Node 19112, 197 bytes ==> 19112}
"""
pattern = r"FGNR_17,([^,]+),DMcode,([^,]+)"
cleaned_data = re.sub(pattern, "", data)
print(cleaned_data)
```
运行此代码将从数据中去除 Fgnr_17 和 DMcode 后面的值。输出结果将是不包含这些内容的字符串。
阅读全文