Php regexp negative lookahead

I am trying to combine all the words enclosed in {}, but not the words with "_loop". I do not see where I am mistaken in my expression.

 $content   = '<h1>{prim_practice_name}</h1><p>{prim_content}</p><p>Our Locations Are {location_loop}{name} - {state}<br/>{/location_loop}</p>';
 $pattern = '/\{(\w*(?!\_loop))\}/';
+5
source share
1 answer

This is because \ w * "eats" the stop word "_loop" before you verify that you do not check the word first (before \ w *), for example the following:

$pattern = '/\{((?!\w*_loop\})\w*)\}/';

or you can use ?< !:

$pattern = '/\{(\w*(?<!_loop))\}/';
+3
source

All Articles