fork download
  1. s = "an example with 'one' word and 'two and three' words inside quotes"
  2. p s.gsub(/('[^']*')|and/) { $1 || '&' }
  3. p s.gsub(/('[^']*')|and/) { |m| m == $~[1] ? $~[1] : '&' }
Success #stdin #stdout 0s 6424KB
stdin
Standard input is empty
stdout
"an example with 'one' word & 'two and three' words inside quotes"
"an example with 'one' word & 'two and three' words inside quotes"