I want to match the string which starts with '#' and ends with space or end of line. I am using the below function to find it.
function getStringsBetween($string, $start, $end)
{
$pattern = sprintf('/%s(.*?)%s/',preg_quote($start), preg_quote($end));
preg_match_all($pattern, $string, $matches);
return $matches[1];
}
I am using the below search
$y = "@!$+$+$+#+ hsjsjenshsjsjsj#hshsjsj ndjdjjdjdn #sem"
$output = getStringsBetween($y,"#"," ");
print_r($output);
the output looks like below.
Array ( [0] => + [1] => hshsjsj )
here it is missing #sem as it is end of the string and it doesn't match the pattern. How can i include end of the string to be space or end of line.