Today I found a way to do a regex find that makes reformatting code easy.

Let’s say we have some code like this:

<p>{{$variable}}<p>;

and you want it formatted like this:

<p>{{ $variable }}</p>;

This is what I prefer because it gives more breathing room and makes the code easier to read. But these can be scattered in many places in your code.

By doing a global find/replace using this regex, you can replace them all in one shot:

\{\{(?! )

It uses a negative lookahead, which means it will find all occurrences of {{ that are not followed by a space. You could find the closing portion by reversing it. Then use the global replace function and make your commit.

Get in, get it done, move on to the next task!

A fast way to reformat code in PHPStorm