Is there a way to check if a group of characters is bordered by certain characters, but not include them in the match, thus preserving them when you call String.replace
for example? Below is the only way I know of. Is there a better way?
let str = '(word)'
let regex = /([^\w])word([^\w])/g
str = str.replace(regex, '$1new word$2')
// str now equals '(new word)'