Matching whitespace and non-whitespace characters with RegEx I just started watching some regex tutorials on Plural Sight just to learn how to write a proper regex expression. So far so good, it's been alright and I decided to test my knowledge on Hackerrank. Although, the tutorial explains how to use PCRE (Perl Compatible Regular Expressions) and ECMAScript engines but I'm comfortable using PCRE at the moment so hence my code is running on PHP.
A brief overview of the question is:

Task
You have a test string S. Your task is to match the pattern XXxXXxXX
Here, x denotes whitespace characters, and X denotes non-white space characters.
Note
This is a regex only challenge. You are not required to write code.
You have to fill the regex pattern in the blank (_________).


$handle = fopen (&quot;php://stdin&quot;,&quot;r&quot;);
$Test_String = fgets($handle);
if(preg_match($Regex_Pattern, $Test_String, $output_array)){
    print (&quot;true&quot;);
} else {
    print (&quot;false&quot;);
}

fclose($handle);
?&gt;


I don't really know much about PHP, all I had to do was fill in the blank so I wrote 2 test cases to see how my regex was doing so far in regex 101 e.g AA AA AA, BB BB BC.

$Regex_Pattern = &quot;/\S{2}\s{1}\S{2}\s{1}\S{2}/&quot;; //Do not delete '/'. Replace __________ with your regex.

Final thoughts: I'm fully aware the example isn't meant to be complicated as it's meant to show how to use \S and \s. I attempted using [\S\s]+\S{2}$ but that wasn't greedy enough as it permits multiple spacing.
Are there more refined ways to do this without using \S &amp; \s and if S &amp;\s can be used differently to achieve the same results?
{1} is redundant, it's better to remove it.
When {2} follows a specific character,
it's is longer to type than the character itself twice,
so I would simply write the character twice.

/\S\S\s\S\S\s\S\S/


As Mike Brant pointed out, some duplication could be reduced by grouping:

/(\S\S\s){2}\S\S/


But this is not as clear as the first example, so I would stick with that.