Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
正規表現を使用して「3 4 +」の文字を「3 + 4」に再配置するにはどうすればよいですか? 私は次のように書いています。
puts ('3 4 +').gsub(/\d \d \W/, '\1 \3 \2')
しかし、何も印刷されていません。私は何を間違っていますか?
でサブグループをキャッチする必要があります()。
()
'3 4 +'.gsub /(\d+) (\d+) (\W)/, '\1 \3 \2'