我想简化以下语句。
if($_=~/^([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])/)
有没有其他方法可以写出上面的语句而不用重复 [0-9a-fA-F] n 次?
最佳答案
您可以使用 Quantifiers
{n} Match exactly n times
if (/^([0-9a-fA-F]{5})/)
同样,您可以使用 POSIX 字符类
xdigit Any hexadecimal digit ("[0-9a-fA-F]").
if (/^([[:xdigit:]]{5})/)
关于regex - Perl 正则表达式简化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5706976/