0

I have a list of IDs that look like <car>-<model>-id, for example:

truck-silverado-id truck-big-ranger-id compact-civic-id

I'm trying to make a regex express to validate the ID. My validation is matching non-ids. Can anyone assist? Here is what I have so far (reduced options for simplicity):

/(truck|truck-big|compact)(-(silverado|ranger|civic)-id)?/gi

Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476
Kevin Danikowski
  • 3,470
  • 4
  • 27
  • 59

1 Answers1

2

Expanding the suggestions into an answer, you need anchors on the regex, and you need to make -id required.

/^(truck|truck-big|compact)(-(silverado|ranger|civic))?-id$/gi