We've determined that this regex works for validating a certain field, but would like it to be shorter since it will be repeated numerous times:
\D\D\d\d\d\D\d\d\D-\d\d\d
What is the 开发者_运维问答shortest notation that would still validate the same as the above regex?
Not really shorter, but maybe more readable.
\D{2}\d{3}\D\d{2}\D-\d{3}
I don't know if it's shorter, but this definitely is easier to read:
\D{2}\d{3}\D\d{2}\D-\d{3}
\D\D\d{3}\D\d\d\D-\d{3}
- only marginally shorter.
Easier to read, although longer: \D{2}\d{3}\D\d{2}\D-\d{3}
What about
\D{2}\d{3}\D\d{2}\D-\d{3}
Since \D{2} are 5 chars, this is shorter:
\D\D\d{3}\D\d\d\D-\d{3}
Another solution, same length but groups 3 characters that are repeated twice
\D{2}\d(\d{2}\D){2}-\d{3}
精彩评论