How do I match a number with a regex in gsub and insert a value?

I need to replace a string like " 123456 " with " ,123456 ".

I have tried this.

 address = address.gsub(/\d{6}/, "") 

But I do not know how to tell gsub use the value associated with " , ".

+4
source share
2 answers

I found the answer here :

 address.gsub /(\d{6})/, ',\1' 
+3
source
 address.gsub! /^/, ',' 

Either you only need this, or you do not have enough context.

0
source

Source: https://habr.com/ru/post/1388622/


All Articles