2009-10-17 64 views
-1

我如何将以下各项与正则表达式匹配?如何在ruby中执行以下正则表达式?

some text includes [any number of character].需要拉动整个[asdfasdf]

@tableid='sometext'我需要拉sometext

mary and drugs我需要拉 “和”,包含空格。

+1

-1不遗余力。 – 2012-03-26 22:35:07

回答

0

尝试这些:

"\[(.*?)\]" 
"@\w+='(.*?)'" 
" +and +" 
2
irb(main):002:0> "some text include [abcdef]".match(/\[(.*)\]/)[1] 
=> "abcdef" 

irb(main):005:0> "@table_id='2356'".match(/'(.*)'/)[1] 
=> "2356" 

irb(main):006:0> "mary and drugs".match(/mary(.*)drugs/)[1] 
=> " and "