标签: ruby regex gsub
我需要用另一个组合替换2个单词的组合而不管它们之间有多少个空格,是否可以用单行中的任何一种通配符?
text.gsub(/Create Proc/i,"Delete Proc") ## single space text.gsub(/Create Proc/i,"Delete Proc") ## 2 spaces text.gsub(/Create Proc/i,"Delete Proc") ## 3 spaces
答案 0 :(得分:1)
text.gsub(/Create\s+Proc/i,"Delete Proc")
\s转义码将在空格(空格和制表符)上匹配
\s
http://rubular.com/r/0bqvUBnojC