我的文件包含 45 个十六进制数字,由空格分隔或 48 个十六进制数字,由空格分隔。我需要所有这些数字单独而不是整体。我目前正在使用蛮力方法来获得 45 个数字。
pattern = re.compile("([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s([0-9a-f]{2})\s")
但是,即使这样,我仍然无法弄清楚如何在 48 十六进制数字实例中提取剩余的三个数字。你能帮我简化这个问题吗?
我会避免像下面这样的解决方案(如果它有效则没有尝试过),因为我稍后将不得不为每个实例拆分字符串,即考虑到它可以提供正确的输出!
(((?:[0-9a-f]{2})\s){48})|(((?:[0-9a-f]{2})\s){45})
谢谢!