2012-11-18 2 views

답변

8

정규식이 필요하지 않습니다. 간단하게 str.squeeze를 사용

str = 'i got sooome screeeewy inpuuuuut' 
=> "i got sooome screeeewy inpuuuuut" 

str.squeeze 
=> "i got some screwy input" 

live demo here를 참조하십시오.

+0

희망 엉망으로 단어 괜찮 : ''good'.squeeze'을 예로서. – tadman

+0

@ tadman, 여기 OP에서 발췌 한 내용이 있습니다. "문법의 정확성은 중요하지 않습니다." –

1

slivu의 대답은 확실히 가장 간결하지만, 당신이 정규식을 사용하는이 , 당신은 사용할 수 있습니다

> 'i got sooome screeeewy inpuuuuut'.gsub(/(\w)\1+/, "\\1") 
=> "i got some screwy input" 
다른 단어로