There is a requirement to detect whether a string is six eight-digit hexadecimal numbers connected by underscores.
For example: "1234567F_1234567F_1234567F_1234567F_1234567F_1234567F"
I write it myself A regular expression is used to match, as follows:
"^[0-9a-fA-F]{8}_[0-9a-fA-F]{8}_[0-9a-fA-F]{8}_[0-9a-fA-F]{8}_[0-9a-fA-F]{8}_[0-9a-fA-F]{8}$"
This regular expression can be matched successfully, but it feels too complicated and has too much repeated content. Can it be simplified?
过去多啦不再A梦2017-06-12 09:27:26
I might write like this^([0-9a-fA-F]{8}_){5}[0-9a-fA-F]{8}$
.
Now that the questioner can use {8}
, you can consider using the first eight hexadecimal digits + '_' as a number to express the number of occurrences.