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>} />
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
GWorking
  • 4,011
  • 10
  • 49
  • 90
  • Have a look here, that should help: https://stackoverflow.com/questions/641407/javascript-negative-lookbehind-equivalent - also note the answer below the accepted one. – Bananaapple Oct 19 '18 at 14:53

1 Answers1

1

I needed the curly braces

<R.Route path={/^\/(?!whatsmyname$).*/} render={() => <div>works!</div>} />
GWorking
  • 4,011
  • 10
  • 49
  • 90