Q:

Looping within a regular expression

can regex able to find a patter to this?

{{foo.bar1.bar2.bar3}}

where in the groups would be

$1 = foo $2 = bar1 $3 = bar2 $4 = bar3 and so on..

it would be like re-doing the expression over and over again until it fails to get a match.
the current expression i am working on is
(?:\{{2})([\w]+).([\w]+)(?:\}{2})

Here's a link from regexr.

http://regexr.com?3203h

--
ok I guess i didn't explain well what I'm trying to achieve here. 
let's say I am trying to replace all 
.barX inside a {{foo . . . }}
my expected results should be
$foo->bar1->bar2->bar3

A:

This should work, assuming no braces are allowed within the match:
preg_match_all(
    '%(?<=     # Assert that the previous character(s) are either
     \{\{      # {{
    |          # or
     \.        # .
    )          # End of lookbehind
    [^{}.]*    # Match any number of characters besides braces/dots.
    (?=        # Assert that the following regex can be matched here:
     (?:       # Try to match
      \.       #  a dot, followed by
      [^{}]*   #  any number of characters except braces
     )?        # optionally
     \}\}      # Match }}
    )          # End of lookahead%x', 
    $subject, $result, PREG_PATTERN_ORDER);
$result = $result[0];

