Is there a way to shorten this regex?

The following regex matches my pattern. But, I wonder if there is a way to cut it. I cannot use \ w because I only need case-sensitive English alphabets. Since the pattern is repeating, I wonder if I can group it, if possible.

([A-Za-z]{5}\.[A-Za-z]{3}\.[A-Za-z]{3}\.[A-Za-z]{3}\.[0-9]{3}\.[0-9]{2})\.([0-9]{8}\-[0-9]{6})\.csv
+3
source share
2 answers

You can shorten this a bit:

([A-Za-z]{5}(\.[A-Za-z]{3}){3}\.[0-9]{3}\.[0-9]{2})\.([0-9]{8}-[0-9]{6})\.csv
+3
source

\dinstead [0-9]- this is an obvious way to shorten it a bit:

([A-Za-z]{5}\.[A-Za-z]{3}\.[A-Za-z]{3}\.[A-Za-z]{3}\.\d{3}\.\d{2})\.(\d{8}\-\d{6})\.csv

Then consolidate the repeating pattern that @anubhava pointed out:

([A-Za-z]{5}\.([A-Za-z]{3}\.){3}\d{3}\.\d{2})\.(\d{8}\-\d{6})\.csv

Case sensitivity from the beginning will slightly reduce the regex ...

(?i)([a-z]{5}\.([a-z]{3}\.){3}\d{3}\.\d{2})\.(\d{8}\-\d{6})\.csv

... .CSV (.. .CSV), , , , .

, 4 , :

(?i)[a-z]{5}\.([a-z]{3}\.){3}\d{3}\.\d{2}\.\d{8}\-\d{6}\.csv
+3

All Articles