Test name | Executions per second |
---|---|
Regex 1 | 8220839.5 Ops/sec |
Regex 2 | 198801.7 Ops/sec |
Split | 13737091.0 Ops/sec |
Substring | 13134690.0 Ops/sec |
var str = 'https://www.testsite.com/some-path/another-path/2019/my-amazing-page-name.html';
str.replace(/^(.*[\\\/])/, '');
str.replace(/([^\/]+)(?=[^\/]*\/?$)/, '');
str.split('/').pop();
str.substring(str.lastIndexOf('/')+1);