Reputation: 20376
I am trying to write a regex to capture all text after the final / in an expression e.g. for myname/is/john, I want to capture "john" but the regex I have written /[^/]*$
returns "/john". How can I get it to return just john and not /john?
Upvotes: 2
Views: 37
Reputation: 24333
s = 'myname/is/john';
r = /\/([^\/]*)$/;
result = r.exec(s)[1];
console.log(result);
Upvotes: 0
Reputation: 180103
If you can rely on the input to contain at least one /
, then you can just match text that does not include it:
[^/]*$
You will get the maximal match.
Upvotes: 4