The problem is that your pattern requires the repetitions to occur immediately after each other, with no whitespace between.
Try adding a \s*
after the alternation to allow for optional whitespace between the repetitions, like this:
(?:(?:border-box|padding-box|content-box)\s*){1,2}
Or even better:
(?:(?:border|padding|content)-box\s*){1,2}
Note that because of the *
, this will also match a string like border-boxborder-box
(no whitespace between repetitions). If this is a problem you can try a pattern like this:
(?:(?:border|padding|content)-box)(?:\s+(?:border|padding|content)-box)?
Note that I've removed the surrounding (…)
since this group would always be identical to the entire match, so it's almost certainly not necessary.