$re = '/\$([\w]+)->([^\W]+)/';
$str = ' @foreach($fsn_uploaded_data as $client_no => $client)
<div class="client" style="border: 1px solid #888; margin-bottom: 10px;">
<h2>{{ $client[\'client_name\'] or \'-\' }}</h2>
<p>{{ $client->postal_address or \'-\' }}, {{ $client->zip_code_postcode or \'-\' }}, {{ $client->city or \'-\' }}, {{ $client->countr_code or \'-\' }}</p>
}
{{-- @foreach($client->delivery_addresses as $delivery_no => $address)
<div class="delivery_addresses" style="border: 1px solid #ddd; margin: 5px;">
<h3>{{ $address->client_delivery_name or \'-\' }}</h3>
<p>{{ $address->delivery_address or \'-\' }}, {{ $address->zip_code or \'-\' }}</p>
</div>
@endforeach --}}
</div>
@endforeach';
$subst = "$\1['\2']";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php