Simplification problem of regular expressions in java or scala
学习ing
学习ing 2017-06-12 09:25:26
0
2
623

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?

学习ing
学习ing

reply all (2)
过去多啦不再A梦

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.

    刘奇

    You can simplify [0-9a-fA-F] again:

    ^([^\W_]{8}_){5}[^\W_]{8}$
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!