<?php

$string = 'жышышышыдыдыжыжыжыж ы';
$result = preg_replace('/(ж|ш)(ы)/', '$1[$2]', $string);
echo $result;