2011-12-09 32 views
0

我定義趕上suche碼「對象」的所有occurancy:簡單的preg_match開始...結束

object InvalidFilterField3: TUNIField 
    FieldType = uftString 
    FieldName = 'PRI_SERIAL' 
    Caption = sdfgsdfgsdfg 
    Category = sdfgsdfgsdfgsdfg 
    Opers = [opEqual, opLike, opInList, opIsNull, opIsNotNull] 
    DefaultOper = opLike 
    FieldIndex = 0 
end 
object UNIField1: TUNIField 
    FieldType = uftDate 
    FieldName = 'PRI_DT' 
    Caption = sdfgsdfgsdfg 
    Category = asdfasdfasdfasdf 
    Opers = [opEqual, opNotEqual, opLarger, opSmaller, opEqualOrLarger, opEqualOrSmaller, opBetween, opIsNull, opIsNotNull, opIn] 
    DefaultOper = opEqual 
    FieldIndex = 1 
end 

認爲必須/object(.*)end/m但它沒有=(

回答

3

你需要傳遞成圖案既DOTALL修飾符(小號)告訴PCRE一個點意味着什麼(包括新行)和ungreedy修飾符(ü,更多的貪婪和改性劑對the PHP manual):

preg_match_all('!object(.*)end!sU', $string, $matches); 
print_r($matches); 
+0

youe示例打印'Array([0] => Array()[1] => Array())' – Subdigger

+0

確實,只是修復了它。即使正如我解釋過的,你必須同時使用s和u修飾符,但我只是在示例中使用了U。 :-) –

+0

tnx。這解決了主要問題。還有一個問題:如果有嵌套對象'object .... object ... end object end end'會怎麼樣? – Subdigger