You mean something like this:
(0|\d+(?:px|em|%))\s(0|\d+(?:px|em|%))\s(0|\d+(?:px|em|%))\s(0|\d+(?:px|em|%))
and replace with
$1 $4 $3 $2
See here at Regexr
Explanation:
This expression consists of 4 capture groups that are equal, so I explain only one.
This is a capture group due to the hte brackets around the expression. The second pair of brackets has ?: After the opening bracket, because of which it is not an exciting group. Its easy to group alternatives, and I don't need the saved partial result.
(0|\d+(?:px|em|%))
This expression matches either 0 or a series of digits ( \d+ ) followed by px , em or % .
These expressions are combined using the space character \s .
source share