python - 如何使用正则表达式打印出哈希键的结果
问题描述
我正在尝试使用 re.search 搜索哈希键并打印结果。
我已经尝试了许多搜索条件,但它什么也没返回。
搜索字符串:
FLASH\hashval.key 234 -A7B865C48E-
用于检索我需要的值的字符串
match = re.search(r'^FLASH\\hashval.key.+\s+(\-\w+\-)\s+', line)
代码片段
def _test_hashval_key(self):
'''
Verify that the hashval.key is correct in the DRP.
'''
tid = 'HashVal'
cmd = 'drpmrs dev=/dev/ro2 filelist'
sts, out = runcmd(cmd)
fnd = False
for line in out.split('\n'):
line = line.strip()
#FLASH\hashval.key 234 -A7B865C48E-
match = re.search(r'^FLASH\\hashval.key.+\s+(\-\w+\-)\s+', line)
if match:
hash = match.group(1)
print hash()
fnd = True
val = -A7B865C48E-
val1 = -EDA6384F89-
val2 = -BF384513DC-
if val == hash:
self._passed(tid, 'hashval.key sys: %s' % (hash))
if val1 == hash:
self._passed(tid, 'hashval.key prd: %s' % (hash))
if val2 == hash:
self._passed(tid, 'hashval.key crp: %s' % (hash))
if not match:
self._failed(tid, 'hashval.key not found')
这就是我想展示的例子:
Test:14 HashVal: crp -A7B865C48E-
解决方案
我能够找出正确的正则表达式
match = re.search(r'^FLASH\\hashval.key.\s+(.*)\-', line)
推荐阅读
- php - 防止覆盖第一行表 PHP MySQL
- flutter - youtube_player_flutter -- 在 Flutter 中搜索时,Youtube 视频会一直播放
- c# - 图例标记子按钮单击在 chrome 中不起作用
- java - 如何使用 BeanUtils 填充复杂的 bean?
- mysql - mysql - 组合连接和联合操作
- scapy - Does scapy works on macOS without problems?
- java - 串行通信中缺少数据
- python - 缓存必须在视图级别、模型或 Django 的序列化程序中实现
- jenkins - 通过在 jenkins slave 中使用现货和按需实例来优化成本的最佳方法是什么?
- python - 如何通过调整大小来绑定事件