如何替换所有也不是空格字符 (\s) 的非单词字符 (\W)?
这是所需的功能:
"the (quick)! brown\n fox".gsub(regex, "#")
=>
“#quick## brown\n fox”
最佳答案
"the (quick)! brown \n fox".gsub(/[^\w\s]/, "#")
通过使正则表达式替换任何不是单词字符或空格字符的内容。
关于 ruby 正则表达式 : replace non-word chars that are not space chars,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10253516/