Ruby regex - gsub only captured group

后端 未结 6 778
夕颜
夕颜 2021-01-03 22:47

I\'m not quite sure I understand how non-capturing groups work. I am looking for a regex to produce this result: 5.214. I thought the regex below would work, bu

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-03 23:06

    You don't need regexp to achieve what you need:

    '1,200.00'.tr('.','!').tr(',','.').tr('!', ',')

    • Periods become bangs (1,200!00)
    • Commas become periods (1.200!00)
    • Bangs become commas (1.200,00)

提交回复
热议问题