preg_replace('/bbbb(.*)dddd/U', '$1bbbbdddd', 'x!!x bbbbbdddd x!!x bbbbaaaaddddd x!!x bbbbcccccddddd');