Sebastian Hungerecker
3/13/2008 9:43:00 PM
Adam Akhtar wrote:
> say i have the string "qxq" and i want to repeat the middle char 4 times
> i could do this
> str = "qxq
> newstring = str.gsub(/(x)/, '\1'*4)
>
> but if i have a string full of x's i.e. "xxx"
> then it will repeat all of them 4 times and thats not what i want to
> do...i just want the middle one to be repeated.
>
> How do i alter that regex to do this???
str.gsub(/(\w)(x)(\w)/, '\1'+'\2'*4+'\3')
HTH,
Sebastian
--
Jabber: sepp2k@jabber.org
ICQ: 205544826