Answers for "ruby regex capture and replace"

0

ruby regex replace capture group

You can't. gsub replaces the entire match; it does not do anything with the captured groups. It will not make any difference whether the groups are captured or not.
In order to achieve the result, you need to use lookbehind and lookahead.

"5,214".gsub(/(?<=\d),(?=\d)/, '.')
Posted by: Guest on February-01-2021

Browse Popular Code Answers by Language