我如何将以下各项与正则表达式匹配?
some text includes [any number of character].
需要拉出整个 [asdfasdf]
@tableid='sometext'
我需要提取 sometext
mary and drugs
我需要拉“和”,包括空格。
答案 0 :(得分: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 "
答案 1 :(得分:0)
试试这些:
"\[(.*?)\]"
"@\w+='(.*?)'"
" +and +"