简体   繁体   中英

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

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

I tried this.

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

But I don't know how tell gsub to use the value matched to concatenate with " , ".

我在这里找到了答案:

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

要么你只需要这个,要么你没有显示足够的背景。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM