[英]Perl Regular Expression simplification
I want to simplify the following statement. 我想简化以下声明。
if($_=~/^([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])/)
Is there an alternate way I can write the above statement without repeating [0-9a-fA-F] n times ? 有没有另外一种方法可以在不重复[0-9a-fA-F]的情况下编写上述语句n次?
You can use Quantifiers 你可以使用量词
{n} Match exactly n times
{n}完全匹配n次
if (/^([0-9a-fA-F]{5})/)
Similarly, you can use a POSIX character class 同样,您可以使用POSIX字符类
xdigit Any hexadecimal digit ("[0-9a-fA-F]").
xdigit任何十六进制数字(“[0-9a-fA-F]”)。
if (/^([[:xdigit:]]{5})/)
尝试这个
if($_=~/^([0-9a-fA-F]{5})/)
甚至
if( /^([0-9a-fA-F]{5})/ )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.