2010-06-26 43 views
1
做正則表達式

嗨,我有一個巨大的下列字符串格式如何在ROR

例如格式:

p=" --0016367d537a47795e0489ecb3c7\nContent-Type: text/plain; charset=ISO-8859-1\n\nok this is tested here\n and again going to test it \n\n\nOn Sat, Jun 26, 2010 at 4:20 PM, kumar \n <[email protected]> wrote:\n\n>" 

從上面的巨大字符串我只需要在它下面的內容。

"ok this is tested here \n and again going to test it" 

我有實現以下正則表達式,但沒有用我的正常exp爲如下

p.match(/(^\n\n*.*\n\n)/) 

不過是格式不返回所需出來放.....任何一個可以請幫助出

回答

2
irb(main):008:0> p.split("\n\n")[1] 
=> "ok this is tested here\n and again going to test it " 
+0

是!!!!!!!!這是一個騙局。謝謝很多S.馬克非常感謝你 – palani 2010-06-26 13:34:27

0

您正在使用\ n,它與backspace不匹配,因爲這是一個關鍵的正則表達式字符。爲了找到\作爲匹配的一部分,您必須使用\\。

下面是我測試過您所需要的組相匹配的例子:

\\n\\n([\s\S]+)\\n\\n\\n