DEV Community

[Comment from a deleted post]
Collapse
 
jonrandy profile image
Jon Randy 🎖️

The replace example is incorrect - it only works with if the first and last characters are /. This is probably better:

let str = '/hello/';

console.log(str.replace(/^.|.$/g,''));
Collapse
 
dewaldcels profile image
Dewald Els • Edited

It is a better solution for sure. Perhaps that doesn't mean the example is incorrect, rather inefficient 😅