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 ?
You can use Quantifiers
{n} Match exactly n times
if (/^([0-9a-fA-F]{5})/)
Similarly, you can use a POSIX character class
xdigit Any hexadecimal digit ("[0-9a-fA-F]").
if (/^([[:xdigit:]]{5})/)
尝试这个
if($_=~/^([0-9a-fA-F]{5})/)
甚至
if( /^([0-9a-fA-F]{5})/ )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.