Hello Programmers, In this post, you will learn how to solve HackerRank Branch Reset Group Solution. This problem is a part of the Regex HackerRank Series.
One more thing to add, don’t straight away look for the solutions, first try to solve the problems by yourself. If you find any difficulty after trying several times, then look for the solutions. We are going to solve the Regex HackerRank Solutions using CPP, JAVA, PYTHON, JavaScript & PHP Programming Languages.

HackerRank Branch Reset Group Solution
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.
Task
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 (_________
).
HackerRank Branch Reset Group Solution in Cpp
HackerRank Branch Reset Group Solution in Java
HackerRank Branch Reset Group Solution in Python
HackerRank Branch Reset Group Solution in JavaScript
HackerRank Branch Reset Group Solution in PHP
$Regex_Pattern = '/^\d\d(?|(---)|(-)|(.)|(:))\d\d\1\d\d\1\d\d$/'; //Do not delete '/'. Replace __________ with your regex.
Disclaimer: This problem (Branch Reset Groups) is generated by HackerRank but the solution is provided by Chase2learn. This tutorial is only for Educational and Learning purposes.