2010-04-01 88 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