【发布时间】:2013-10-19 06:46:29
【问题描述】:
给定字符串:
"hello %{one} there %{two} world"
此代码不起作用:
s = "hello %{one} there %{two} world"
r = Regexp.new(/(%{.*?})+/)
m = r.match(s)
m[0] # => "%{one}"
m[1] # => "%{one}"
m[2] # => nil # I expected "%{two}"
但在Rubular 上,相同的正则表达式(%{.*?}) 可以工作并返回%{one} 和%{two}。
我做错了什么?
【问题讨论】: