-1

I am reading a javascript file which has few issues and I come across with a RegEx which looks like

/^(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z){3}\d{3}|(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z){3}(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z){0,1}$/; 

Firstly what it actually matches and how can I simplify it

user3733648
  • 1,323
  • 1
  • 10
  • 25

1 Answers1

0

That's functionally similar to:

/^([a-z]){3}\d{3}|([a-z]){3}([a-z]){0,1}$/;

This basically captures:

  • From the start of the string
  • 3 characters in the a-z range followed by 3 digits, or
  • 3 characters in the a-z range followed by 0 or 1 character in the a-z range.
Cerbrus
  • 70,800
  • 18
  • 132
  • 147
  • I don't think you need the `()` anymore since they where is in order to apply the `|` – kaldoran Apr 19 '17 at 09:58
  • @kaldoran: Depends on what they were using it for (e.g., were they use the capture group). If it had been a non-capturing group `(?:a|b|...)`, it would definitely be unnecessary. – T.J. Crowder Apr 19 '17 at 09:59
  • @kaldoran: If they were being used as capture grops, you need'm. – Cerbrus Apr 19 '17 at 10:06