HackerRank Positive Lookbehind Solution

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

HackerRank Positive Lookbehind Solution
HackerRank Positive Lookbehind 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 Lookbehind Solution

(?<=regex_2)regex_1
The positive lookbehind (?<=) asserts regex_1 to be immediately preceded by regex_2. Lookbehind is excluded from the match (do not consume matches of regex_2), but only assert whether a match is possible or not.

Task

You have a test String S.
Write a regex which can match all the occurences of digit which are immediately preceded by odd digit.

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

HackerRank Positive Lookbehind Solutions in Java

public class Solution {    
    public static void main(String[] args) {
        
        Regex_Test tester = new Regex_Test();
        tester.checker("(?<=[13579])(\\d)"); //Use '\\' instead of '\'.
    
    }
}

HackerRank Positive Lookbehind Solutions in Python

Regex_Pattern = r"(?<=[13579])\d"

HackerRank Positive Lookbehind Solutions in JavaScript

HackerRank Positive Lookbehind Solutions in PHP

$Regex_Pattern = '/(?<=[13579])\d/'; //Do not delete '/'. Replace __________ with your regex. 

Disclaimer: This problem (Positive Lookbehind) is generated by HackerRank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Next: HackerRank Backreferences To Failed Groups Solution

Sharing Is Caring

Leave a Comment