Jumpy N Jumpy N - 1 year ago 35
PHP Question

Php regex, match if { } characters isn't presented

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:


Here's my regex pattern so far:

Current pattern matches both


But it should only match

Any help would be greatly appreciated, Jumpy.


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);

Ideone Demo