let text = "'I'm the cook,' he said, 'it's my job.'"; const actionReplace = string.replace(/(^')|('$)|('(?=.*)(?=\s))|(?: '(?=.*))/g, "#");
}
console.log(repla
我正在尝试编写正则表达式来匹配不包含在引号中的字符串(双引号或单引号),但是到目前为止,我所能做的最好的事情就是使用一个循环来遍历字符串的所有字符。必须有一个更简单、更优雅的解决方案。示例:如果尝试用bar替换foo,字符串hello foo!将变为hello bar!,但字符串you said "my name is foo"将保持不变。有没有人可以使用regexp来帮助实现上