Ruby 求一个正则表达式的解析

scuwolf · January 02, 2014 · Last by scuwolf replied at January 02, 2014 · 1790 hits
1.9.3p385 :001 > 1999995.99.to_s.reverse.scan(/(?:\d*\.)?\d{1,3}-?/).join(',').reverse
 => "1,999,995.99"

这里/(?:\d*.)?\d{1,3}-?/这个正则表达式,能否给分解下,尤其是 ?\d{1,3}-? 这个用法,以前没见过

/
  (\d*.)? # 可选组
  \d{1,3} # 1到3个数字
  -? # 最后的减号也是可选的
/x

#1 楼 @luikore 多谢,懂了。thx

You need to Sign in before reply, if you don't have an account, please Sign up first.