Take the 2-minute tour ×

I ned to catch all occurancy of "object" in suche code:

object InvalidFilterField3: TUNIField
  FieldType = uftString
  FieldName = 'PRI_SERIAL'
  Caption = sdfgsdfgsdfg
  Category = sdfgsdfgsdfgsdfg
  Opers = [opEqual, opLike, opInList, opIsNull, opIsNotNull]
  DefaultOper = opLike
  FieldIndex = 0
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

think that must be /object(.*)end/m but it does not =(

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You need to pass up into the pattern both the dotall modifier (s) to tell PCRE that a dot means anything (including newlines) and the ungreedy modifier (U, more on greediness and modifiers on the PHP manual):

preg_match_all('!object(.*)end!sU', $string, $matches);
share|improve this answer
youe example prints Array ( [0] => Array ( ) [1] => Array ( ) ) –  Subdigger Dec 12 '11 at 9:03
True, just fixed it. Even though as I explained you must use both s and U modifiers, I just used U in the example. :-) –  Diego Agulló Dec 12 '11 at 17:22
tnx. this resolves the main problem. just one more question: what if there are nested objects object .... object ... end object end end? –  Subdigger Dec 14 '11 at 11:40
add comment

Your Answer


