You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a route /:parameter and if someone pings that route I should serve him certain page (React App)
So what I need is some kind of regexp that wont match certain words...
Regular expression should be ^(?!.*(foobar1|\/foobar2)).*$
https://pshrmn.github.io/route-tester/#/ I've used this tool for testing and entered various combinations, such as /parameter(?!.*(foobar1|\/foobar2)) but no luck...
So test case should be
if path is /foobar3 it should return page
if path is /foobar2 or /foobar3 it should return null
The text was updated successfully, but these errors were encountered:
Does “the best regex trick” work for your needs? I think it would express your example as /(?:foobar2|foobar3|(foobar1))/, but I admit I couldn’t figure out how to translate it into a form that the linked route-tester page was happy with.
If someone wants to propose expanding the existing syntax to support this, I'm happy to review.
Otherwise I'd suggest maybe filing a ticket with the libraries using this package to support this feature. It's definitely easier than trying to construct a negative regex. For example, in something like Express you can have middleware that runs and write a line of code that says parameter !== 'foobar1' to skip the middleware on that condition.
I have a route
/:parameter
and if someone pings that route I should serve him certain page (React App)So what I need is some kind of regexp that wont match certain words...
Regular expression should be
^(?!.*(foobar1|\/foobar2)).*$
https://pshrmn.github.io/route-tester/#/ I've used this tool for testing and entered various combinations, such as
/parameter(?!.*(foobar1|\/foobar2))
but no luck...So test case should be
if path is
/foobar3
it should return pageif path is
/foobar2
or/foobar3
it should returnnull
The text was updated successfully, but these errors were encountered: