regex - Insert exactly one space between pattern of one or more characters using Ruby -
i have string.
'abcxdefxabcyxyabc'
i want have them separated 1 space. known patterns in string are:
abc x def y
the resulting string should be
'abc x def x abc y x y abc' = 'abcxdefxabcyxyabc' b = a.gsub(/[^ ]\((abc|def|x|y)\)[^ ]/,' \1 ')
i not having luck gsub regex.
thanks help.
you're making complicated:
1.9.3p194 :001 > = 'abcxdefxabcyxyabc' => "abcxdefxabcyxyabc" 1.9.3p194 :002 > a.gsub(/abc|def|x|y/, '\0 ').strip => "abc x def x abc y x y abc"
Comments
Post a Comment