我有一個多行字符串,例如:如何在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:]])是一個積極的倒序,它要求在連字符前加一個字母。 –