<?php $string = "abcdefg"; $mystring = preg_match("/a(.+)d/", $string, $str); echo $str; // return 'bc'?>