2010-04-01 86 views
0

好吧,我不能完全弄清楚如何做到這一點。正則表達式來提取這個半格式化數據

鑑於以下文字:

Roland AX-1: 


/start 
Roland's AX-1 strap-on remote MIDI controller has a very impressive 45-note velocity sensitive keyboard, and has switchable velocity curves, goes octave up/down, transpose, split/layering zones, and has fun tempo control for sequencers and more. Roland's AX-1 comes with a built-in GS control for total MIDI control of GM/GS synths. Its "Expression Bar" can control pitch and mod via an almost ribbon-like controller. It's also the newest and most advanced remote controller for your synths or midi modules. 
/end 

Roland AX-7: 

/start 
Roland's AX-7 builds on the infamous Roland AX-1 design. You just strap it on and put it to the front of the stage. Offering several controllers, such as: a D-Beam, then you can open the door to amazing live performance. 7-segment LED display, larger patch memory (Around 128 patches with MIDI data backup), and comes with GM2/GS compatibility make it extra easy to use. The 45-note, velocity-sensitive keyboard. 5 realtime controllers including a data entry knob, touch controller knob, opression bar, a hold button, and D-Beam. 128 patches with MIDI data backup. 2 MIDI zones. 
/end 

我嘗試使用以下命令:

/^([\w\d \-]*):\s\s\s\s^\/start([^\:]*)\/end$/im 

你可以在這裏看到rubular:

http://rubular.com/r/BVRRHsnWdp

感謝任何幫助。我想我試圖匹配文本塊直到我遇到下一個標題總是以:$

回答

1

您的解決方案的問題是[^\:]*不允許段落中的任何冒號,但有一些。嘗試一下,使用非貪婪的匹配段落:

/^([\w\d \-]*):\s+^\/start(.*?)\/end$/im 
+0

謝謝,我知道這是一些與貪婪/非貪婪,爲什麼我匹配的一切。另外,\ s +很有幫助,我可以看出爲什麼它更有用。 – Codygman 2010-04-01 22:44:15

0

看看Ruby的「觸發器」操作符。這對於這類問題非常有用。

When would a Ruby flip-flop be useful?」 涵蓋了這一點。

+0

我仍在閱讀,但看起來這將在未來非常有用!感謝一堆人:) – Codygman 2010-04-01 22:44:59