使用正则表达式从二进制文件中提取字符串并转换为 ASCII -- 使用 Perl
试图弄清楚如何从二进制文件中提取字符字符串并将其转换为 ascii。这些字符是条形码,前面是常量文本字符串。我的想法是找出字符串常量字符串的十六进制模式是什么,并根据该模式提取字符串,然后将十六进制转换为 ASCII。
问题是我不知道如何让 perl“读取”文件,或“查看”它所看到的内容。这意味着如果文件是文本文件,可能会执行类似的操作 - Perl:使用正则表达式从文本中提取数据 - 但我不知道如何弄清楚我的目标二进制模式是什么;也就是说,我在这里发布了此数据的一个视图: Extracting “使用 Perl 从 HEX 文件中获取纯文本”标头
我如何在 Perl 中执行此操作?
Trying to figure out how to extract a string off characters from a binary file and convert them to ascii. The characters are a barcode, which is preceded by a constant string of text. My thought is to figure out what the HEX pattern is for the string constant string and extract the string based on that, then convert the HEX to ASCII.
Problem is I don't know how get perl to "read" the file, or "see" what it's seeing. Meaning that if the file was a text file, might do something like this - Perl: extracting data from text using regex - but I don't know how to figure out what the binary pattern I'm targeting is; that said, I've posted one view of this data here: Extracting “plaintext” header from HEX file using Perl
How do I do this in Perl?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种简单的方法:
这将打印由
\w{2,}
组成的所有字符串,即专门的遗留单词字符,并且至少其中两个。Here's one easy way to do it:
That'll print all strings composed of
\w{2,}
, i.e. legacy word characters exclusively, and at least two of them.