2014-01-26 47 views
1

OK之間的內容,所以,讓我們說我有一些文字,如:獲取匹配外花括號

Any random content here 
{{mycontent 
more content goes here 
{{curly braces may also appear in here}} 
{even single ones} 

}} 

And more content goes here... 

我需要{{mycontent及其相應}}右括號之間取的部分。

你會如何去在RegEx(這是一個必須)?

+0

您使用什麼語言?你還試過了什麼? – HamZa

+0

@HamZa嗯,我使用PHP,但這不是重點。順便說一句,我已經能夠實現我最初的要求了;但在PHP中,不在RegEx中。正則表達式中嵌套模式總是困擾我。 (我知道這可能不是解決問題的最佳方法,但它*有......) –

+0

既然你已經向社區承諾,那麼我會幫你做這個...... [玩得開心] (http://regex101.com/r/qK6mA7) – HamZa

回答

-2

/\{{2}(.*)\}{2}/s

這將匹配2個大括號包括新線之間的任何東西。

其結果將是

0 => string '{{mycontent 
more content goes here 
{{curly braces may also appear in here}} 
{even single ones} 

}}' 
+0

嗯,你只是依靠貪婪。這樣的事情會失敗'{{help}} {{you}}' – HamZa

+0

呃,這個失敗... http://regexr.com?384c1 –