2009-10-17 7 views
-1

Comment puis-je faire correspondre chacun des éléments suivants avec regex?Comment puis-je faire l'expression rationnelle suivante dans ruby?

some text includes [any number of character]. besoin de tirer l'ensemble [asdfasdf]

@tableid='sometext' J'ai besoin de tirer le someText

mary and drugs je dois tirer "et", espaces compris.

+1

-1 pour aucun effort. –

Répondre

0

Essayez:

"\[(.*?)\]" 
"@\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 " 
Questions connexes