<script> var str = "bbb /aaa\\ bbb /ccc\\"; document.write("Ответ: " + str.replace(/\/.+?\\/g, "/!\\")); </script>