【发布时间】:2014-12-11 18:01:27
【问题描述】:
我正在尝试逐行解析文件并查看处理器发出的数据包数据,这些数据基本上以字母数字字符表示。我用 Python 编写了一个正则表达式来读取模式并将数据包数据存储在一个列表中。
示例行:
Date Time ProcessName ActivityName : 55 34 00 aa c9 00 11 45 55
我的正则表达式:
r'([^\s]*?)\s([^\s]*?)\s([^\s]*?)\s([^\s]*?)\s(R.*?:)\s(\d|\D|\s)+$'
我必须将数据包数据 [: 之后显示的数字] 添加到列表中并执行一些模式处理活动。当我运行我的脚本并打印 match.group(6) 时,它只是在列表中打印了一堆 '\n' 。
我的脚本的 sn-p:
regex = r'([^\s]*?)\s([^\s]*?)\s([^\s]*?)\s([^\s]*?)\s(R.*?:)\s(\d|\D|\s)+$'
pattern = re.compile(regex)
for line in content:
match = pattern.search(line)
if match:
print match.group(6)
我应该如何使用正则表达式读取一组字母数字字符?
【问题讨论】:
标签: python regex alphanumeric