问题
I'm currently working on my own template engine for educational purposes.
Now I'm stuck at this part where I want to match if the string contains the following for e.g:
$article.author
Here's my regex pattern so far: http://www.phpliveregex.com/p/fx2
Current pattern matches both
{$article.author}
and $article.author
.
But it should only match $article.author
.
Any help would be greatly appreciated, Jumpy.
回答1:
You need to use anchors for finding exact match as
^\$[^|{}]*$
Regex Demo
PHP Code
$re = "/^\\$[^|{}]*$/m";
$str = "\$article.author\n{\$article.timestamp}";
preg_match_all($re, $str, $matches);
print_r($matches);
Ideone Demo
回答2:
Is this what you are looking for?
^\$.*
http://www.phpliveregex.com/p/fx3
来源:https://stackoverflow.com/questions/36966076/php-regex-match-if-characters-isnt-presented