Hello Programmers, In this post, you will learn how to solve HackerRank Positive Lookahead 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 Positive Lookahead Solution
regex_1(?=regex_2)
The positive lookahead (?=) asserts regex_1
to be immediately followed by regex_2
. The lookahead is excluded from the match. It does not return matches of regex_2
. The lookahead only asserts whether a match is possible or not.

Task
You have a test string S.
Write a regex that can match all occurrences of o
followed immediately by oo
in S.
Note
This is a regex only challenge. You are not required to write code.
You have to fill the regex pattern in the blank (_________
).
HackerRank Positive Lookahead Solution in Cpp
HackerRank Positive Lookahead Solution in Java
public class Solution { public static void main(String[] args) { Regex_Test tester = new Regex_Test(); tester.checker("o(?=oo)"); //Use '\\' instead of '\'. } }
HackerRank Positive Lookahead Solution in Python
Regex_Pattern = r'o(?=oo)' # Do not delete 'r'.
Positive Lookahead Solution in JavaScript
var Regex_Pattern = /o(?=oo)/g; //Do not delete `/` and `/g`.
Positive Lookahead Solution in PHP
$Regex_Pattern = '/o(?=oo)/'; //Do not delete '/'. Replace __________ with your regex.
Disclaimer: This problem (Positive Lookahead) is generated by HackerRank but the solution is provided by Chase2learn. This tutorial is only for Educational and Learning purposes.