HackerRank Positive Lookahead Solution

Hello Programmers, In this post, you will know how to solve the HackerRank Positive Lookahead Solution. This problem is a part of the Regex HackerRank Series.

HackerRank Positive Lookahead Solution
HackerRank Positive Lookahead Solutions

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.

HackerRank Positive Lookahead Solution

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.


You have a test string S.
Write a regex that can match all occurrences of o followed immediately by oo in S.


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 Solutions in Cpp

HackerRank Positive Lookahead Solutions 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 Solutions in Python

Regex_Pattern = r'o(?=oo)'	# Do not delete 'r'.

HackerRank Positive Lookahead Solutions in JavaScript

var Regex_Pattern = /o(?=oo)/g;	//Do not delete `/` and `/g`.

HackerRank Positive Lookahead Solutions 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 BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Next: HackerRank Negative Lookahead Solution

Leave a Reply

Your email address will not be published. Required fields are marked *