我有一个多行字符串,例如:如何在Ruby中使用换行符连接单词?
"The wolverine is now es-
sentially absent from
the southern end
of its European range."
我要的是:在以前的行删除连字符和串联词。 结果,应该是这样的:
"The wolverine is now essentially
absent from
the southern end
of its European range."
为了安全起见,也许's.gsub(/(<= [[?:阿尔法:]]) - \ S * \ n \ S */“”)'。 –
这里有点松懈是件好事。尾随空间经常发生意外。 – tadman
如果正则表达式是'r = /(?<= [[:alpha:]]) - \ s * \ n \ s * /',“狼本质上是es- \ n”.gsub(r,' ')#=>“狼獾现在基本上是”'和'“111-222- \ n3333”.gsub(r,'')#=>“111-222- \ n3333”'(保留中断)。 '(?<= [[:alpha:]])是一个积极的倒序,它要求在连字符前加一个字母。 –