Test name | Executions per second |
---|---|
Regex 1 | 6746372.0 Ops/sec |
Regex 2 | 184862.4 Ops/sec |
Split | 11369295.0 Ops/sec |
Substring | 11318999.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);