tags:

views:

46

answers:

2

how do i match each of the following with regex ?

some text includes [any number of character]. need to pull the entire [asdfasdf]

@tableid='sometext' I need to pull the sometext

mary and drugs I need to pull " and ", spaces included.

A: 

Try these:

"\[(.*?)\]"
"@\w+='(.*?)'"
" +and +"
Rubens Farias
+2  A: 
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 "
pierr