I\'m working with a Google API that returns IDs in the below format, which I\'ve saved as a string. How can I write a Regular Expression in javascript to trim the string to
This should work:
last = id.match(/\/([^/]*)$/)[1];
//=> nabb80191e23b7d9
this is easy to understand (?!.*/).+
let me explain:
first, lets match everything that has a slash at the end, ok? that's the part we don't want
.*/
matches everything until the last slash
then, we make a "Negative lookahead" (?!)
to say "I don't want this, discard it"
(?!.*)
this is "Negative lookahead"
Now we can happily take whatever is next to what we don't want with this
.+
YOU MAY NEED TO ESCAPE THE / SO IT BECOMES:
(?!.*\/).+