简体   繁体   English

在Perl中使用Regex查找空字符

[英]Finding null character using Regex in Perl

I want to find the null characters in an array, which I have. 我想在数组中找到空字符。 I tried displaying the ASCII value and it printed 0 (So I am confirmed it is a null value). 我尝试显示ASCII值并将其打印为0(因此我确认它为空值)。 How do I write a regex to filter out those values. 如何编写正则表达式以过滤出这些值。

I wrote : 我写 :

m/^$/ig 

which really didn't help me. 这真的没有帮助我。 Does anybody know how to match a null character ? 有人知道如何匹配空字符吗?

You can use \\x followed by the hex code of an ASCII character to match that ASCII character. 您可以使用\\x后跟ASCII字符的十六进制代码来匹配该ASCII字符。

Eg /\\x3F/ will match a "?", /\\x46\\x4F\\x4F/ to match "FOO". 例如/\\x3F/将匹配一个“?”, /\\x46\\x4F\\x4F/匹配一个“ FOO”。

See it here on Regexr 在Regexr上查看

So /\\x00/ would match the NULL character. 因此/\\x00/将匹配NULL字符。

you can use \\0 to find null character. 您可以使用\\0查找空字符。 (but do not follow this with another digit) (但不要在此后面加上其他数字)

0x0 should do the trick. 0x0应该可以解决问题。

0x[0-9A-F] to find any hex char 0x [0-9A-F]查找任何十六进制字符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM