0

How do I rearrange the characters in '3 4 +' to '3 + 4' using regexp? I've written the following:

puts ('3 4 +').gsub(/\d \d \W/, '\1 \3 \2')

But nothing is being printed. What am I doing wrong?

4

1 回答 1

2

您需要通过().

'3 4 +'.gsub /(\d+) (\d+) (\W)/, '\1 \3 \2'
于 2012-09-06T01:36:50.687 回答