Hello Programmers, In this post, you will learn how to solve HackerRank Capturing & Non-Capturing Groups 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 Capturing & Non-Capturing Groups Solution
()
Parenthesis ( ) around a regular expression can group that part of regex together. This allows us to apply different quantifiers to that group.
These parenthesis also create a numbered capturing. It stores the part of string matched by the part of regex inside parentheses.
These numbered capturing can be used for backreferences. ( We shall learn about it later )

(?: )
(?: ) can be used to create a non-capturing group. It is useful if we do not need the group to capture its match.
Task
You have a test String S.
Your task is to write a regex which will match S with the following condition:
- S should have 3 or more consecutive repetitions of
ok
.
Note
This is a regex only challenge. You are not required to write a code.
You have to fill the regex pattern in the blank (_________
).
HackerRank Capturing & Non-Capturing Groups Solution in Cpp
HackerRank Capturing & Non-Capturing Groups Solution in Java
public class Solution { public static void main(String[] args) { Regex_Test tester = new Regex_Test(); tester.checker("((?:ok){3,})"); } }
HackerRank Capturing & Non-Capturing Groups Solution in Python
Regex_Pattern = r'(ok){3,}' # Do not delete 'r'.
HackerRank Capturing & Non-Capturing Groups Solution in JavaScript
var Regex_Pattern = /(?:ok){3}/; //Do not delete '/'. Replace __________ with your regex.
HackerRank Capturing & Non-Capturing Groups Solution in PHP
$Regex_Pattern = "/(ok){3,}/"; //Do not delete '/'. Replace __________ with your regex.
Disclaimer: This problem (Capturing & Non-Capturing Groups) is generated by HackerRank but the solution is provided by Chase2learn. This tutorial is only for Educational and Learning purposes.