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

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -