1

As said in Regex: match everything but in order to match everything but a string, you can use ^(?!foo$).*

As seen here https://regex101.com/r/9khSXB/2

But this doesn't work when using https://www.npmjs.com/package/path-to-regexp specifically within ReactJS Routing (error -> invalid path)

<R.Route path="/^(?!\/whatsmyname$).*" render={() => <div>works!</div>} />

(also seen here http://forbeslindesay.github.io/express-route-tester/)

How can I write this regex in a node-friendly style?

UPDATE: this does work, you need the curly braces

<R.Route path={/^\/(?!whatsmyname$).*/} render={() => <div>works!</div>} />
1

1 Answer 1

1

I needed the curly braces

<R.Route path={/^\/(?!whatsmyname$).*/} render={() => <div>works!</div>} />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.