HackerRank Negative Lookbehind Solution

Hello Programmers, In this post, you will learn how to solve HackerRank Negative Lookbehind 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 Negative Lookbehind Solution
HackerRank Negative Lookbehind Solution

HackerRank Negative Lookbehind Solution

(?<!regex_2)regex_1
The negative lookbehind (?<!) asserts regex_1 not 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.

HackerRank Negative Lookbehind Solution

Task

You have a test String S.
Write a regex which can match all the occurences of characters which are not immediately preceded by vowels (a, e, i, u, o, A, E, I, O, U).

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 (_________).

JavaScript do not support lookbehind.

HackerRank Negative Lookbehind Solution in Cpp

HackerRank Negative Lookbehind Solution in Java

public class Solution {    

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

HackerRank Negative Lookbehind Solution in Python

Regex_Pattern = r"(?<!(a|e|i|u|o|A|E|I|O|U))."	# Do not delete 'r'.

Negative Lookbehind Solution in JavaScript

Negative Lookbehind Solution in PHP

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

Disclaimer: This problem (Negative Lookbehind) is generated by HackerRank but the solution is provided by Chase2learn. This tutorial is only for Educational and Learning purposes.

Sharing Is Caring