0

I am struggling with the problem that I want a regex to only match a part of a string.

Example: "item/12/settings" should match the regex. But if there is a / after "settings", followed by anything, it should not match. E.g. "item/12/settings/option" should not match.

I have tried something like: /\w+\/\d+\/\w+/g but this also matches "item/12/settings/option".

How can I tell the regex to only match a string like /\w+\/\d+\/\w+/g and nothing else? This seems to be trivial, but I am fairly new to using regex and I can't quite wrap my head around it yet.

armmie
  • 25
  • 2
  • 8
  • 1
    Add the anchors `^` & `$`. `/^\w+\/\d+\/\w+$/` – Tushar Dec 07 '16 at 10:48
  • Thanks, I tried something like adding `\/{0}` so that there would be no tailing slash and other silly stuff which did not work. Now it's obvious to me since i spend the day reading up on RegEx. – armmie Dec 07 '16 at 16:29

0 Answers0