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
  • 607,720
  • 39
  • 448
  • 563
Kevin Danikowski
  • 4,620
  • 6
  • 41
  • 75

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