1

I'm trying to match the following string a2eaa37edefd4a1e9bb0d082e441cd4e

When trying my regex in node, I'm getting Invalid regular expression, valid group

I have learned that not all flavors of javascript supports positive lookbehind

var url = 'http://file-store.example.local/files/a2eaa37edefd4a1e9bb0d082e441cd4e+1a3e5372-8fb2-44df-82ed-5603e3a1d72c'

var regex = /(?<=files\/)(.*?)(?=\+|\-)/g;
 
console.log(url.match(regex));

Any ideas on how I can get same results with different regex?

Deano
  • 11,582
  • 18
  • 69
  • 119
  • The answer to your question is that the pattern `/files\/(.*?)(?=\+|\-)/` would do just fine, other than that now `files/` would appear as a prefix to your output. To get around that, look into using capture groups, which also is a way to exclude `files/` from appearing. – Tim Biegeleisen Feb 20 '19 at 14:36
  • 1
    See https://jsfiddle.net/wiktor_stribizew/vL9ujam2/, based on [the accepted answer](https://stackoverflow.com/a/3569116/3832970). – Wiktor Stribiżew Feb 20 '19 at 14:37
  • @WiktorStribiżew big + for cleaner code – Deano Feb 20 '19 at 15:14

0 Answers0