在ruby中查找匹配字符串的模式

在ruby中查找匹配字符串的模式,ruby,regex,Ruby,Regex,在上面的代码中,我想提取匹配的括号,其中包含作为一个整体表达式的it中的文本 我的意思是我想通过我的代码得到以下结果: name="(this is a message ) (other message)"; res=name.scan(/(\(.*\))/m); puts res.join("###"); 也就是说,res的长度应该是2而不是1, 但在我的代码中,我总是得到: (this is a message )###(other message) 我的模式一定有问题,有人能帮

在上面的代码中,我想提取匹配的括号,其中包含作为一个整体表达式的it中的文本

我的意思是我想通过我的代码得到以下结果:

name="(this is 
a message
)

(other message)";

res=name.scan(/(\(.*\))/m);
puts res.join("###");
也就是说,res的长度应该是2而不是1, 但在我的代码中,我总是得到:

(this is 
a message
)###(other message)
我的模式一定有问题,有人能帮我解决吗?

如果要使用匹配项,请将regexp行更改为:

(this is 
a message
)
(other message)
res=name.scan(/(\(.*?\))/m);