Или, более конкретно (замените /#
или #/
):
message.replace(/\/#|#\//g, "")
(Вы должны выйти из /
с \/
)
Еще один более сложныйподход, который может или не может работать в зависимости от ваших случаев использования:
let message = 'Hello my name is /# Jane #/, if from /# company#/. Could you please call me back.';
// replace in pairs and take care of extra whitespace
let regex = /\/#\s*(\w+)\s*#\//g;
message = message.replace(regex, "$1");
console.log(message);