# Branch Reset Groups – HackerRank Solution

In this post, we will solve Branch Reset Groups HackerRank Solution. This problem (Branch Reset Groups) is a part of HackerRank Regex series.

NOTE – `Branch reset group is supported by Perl, PHP, Delphi and R.`

(?!regex)
AÂ branch reset groupÂ consists of alternations and capturing groups.Â (?|(regex1)|(regex2))
Alternatives in branch reset group share same capturing group.

You have a test stringÂ S.
Your task is to write a regex which will matchÂ S, with following condition(s):

• SÂ consists of 8 digits.
• SÂ must have “—“, “-“, “.” or “:” separator such that stringÂ SÂ gets divided inÂ 4Â parts, with each part having exactly two digits.
• SÂ string must have exactly one kind of separator.
• Separators must have integers on both sides.

ValidÂ S

``````12-34-56-78
12:34:56:78
12---34---56---78
12.34.56.78``````

Invalid S

``````1-234-56-78
12-45.78:10``````

Note

This is a regex only challenge. You are not required to write any code.
You only have to fill the regex pattern in the blank (`_________`).

## Branch Reset Groups – HackerRank Solution

### PHP

```<?php
\$Regex_Pattern = '/^\d{2}(-(?:--)?|\.|:)\d{2}\1\d{2}\1\d{2}\$/'; //Do not delete '/'. Replace __________ with your regex.

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

fclose(\$handle);
?>
```

Note: This problem (Branch Reset Groups) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.