python的字节的正则
我想在以下字节中提取10.00毫升:b'\ x0200s10.00ml \ x03' 因此,我尝试在200s和\ x03之间提取10.00毫升:
result = re.search(b'200S(.*)x03', b'\x0200S10.00ML\x03')
没有可行的元素:
AttributeError: 'NoneType' object has no attribute 'group'
仅使用字符串,我有一个最低的工作示例:
test_string = 'a3223b'
result = re.search('a(.*)b', test_string)
print(result.group(1))
I would like to extract 10.00ML in following byte: b'\x0200S10.00ML\x03'
So I've tried extracting the 10.00ML between 200S and \x03:
result = re.search(b'200S(.*)x03', b'\x0200S10.00ML\x03')
which didn't work, no element was found:
AttributeError: 'NoneType' object has no attribute 'group'
Using only strings I have a minimum working example:
test_string = 'a3223b'
result = re.search('a(.*)b', test_string)
print(result.group(1))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
请注意,
\ x02
和\ x03
是文本控制字符的启动和开始,因此您无法将其匹配为文字文本。You can use
Note that
\x02
and\x03
are START OF HEADING and START OF TEXT control chars, so you cannot match them as literal text.