I’m having trouble with a regex, so I figured I’d ask here. Basically, I need it to match URI’s for a collection, except for a certain one (/new).
i.e.:
/properties # match
/properties/25 # match
/properties/new # rejected
I’ve tried variations on the following, to no avail:
/properties(^(/new)).*
I think my trouble is with the negation, but I can’t quite grok what I’m meant to be doing.. An explanation with the solution would be much appreciated!
^negates inside a character class (a group of characters in any order surrounded by[ ]. You need to use?!. You also shouldn’t use.*. It doesn’t add anything. If you want to match anything you just don’t put anything :). Also you don’t need to capture the match. Depending on how you’re setting it up you may also need to escape the slashes (/)Try this:
\/properties(?!\/new)