gpt4 book ai didi

perl - 检查字符串是否为以 "0x..."Perl 开头的十六进制

转载 作者:行者123 更新时间:2023-12-02 09:32:19 24 4
gpt4 key购买 nike

我如何检查一个字符串:

  1. 以“0x”开头
  2. 是一个有效的十六进制数

例如:

# Returns false
$string = "0213"

# Returns false
$string = "0xHHH"

# Returns true
$string = "0x123456789abcdefABCDEF"

最佳答案

以下操作返回一个 bool 值。

$string =~ /^0x[0-9A-F]+$/i

关于perl - 检查字符串是否为以 "0x..."Perl 开头的十六进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31661087/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com