If you are looking for name between a <p> tags and double opening and closing curly braces {{ }}, you could also do it like this:
<p>{{\K.+?(?=}}<\/p>)
Explanation
- Match
<p>{{
- Reset the starting point of the reported match
\K
- Match any character one or more times (this will be the value you are looking for)
- A positive lookahead
(?=}}<\/p>) which asserts that what follows is }}</p>
You can use preg_match_all to find all of the matches, or use preg_match to return the first match.
Output
Your code could look like:
$subject="<p>{{name}}</p>";
$pattern="/<p>{{\K.+?(?=}}<\/p>)/";
$success = preg_match($pattern, $subject, $match);
if ($success) {
$str = substr($match[0], 5,-2);
echo $str;
} else {
echo 'not match';
}
Note that $str will be false in this case using substr.