Hello Programmers, In this post, you will learn how to solve HackerRank matching specific string 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 matching specific string solution
Regular expression (or RegEx)
A regular expression is a sequence of characters that define a search pattern. It is mainly used for string pattern matching.

Regular expressions are extremely useful in extracting information from text such as: code, log files, spreadsheets, documents, etc.
We can match a specific string X in a test string S by making our regex pattern X. This is one of the simplest patterns. However, in the coming challenges, we’ll see how well we can match more complex patterns and learn about their syntax.
Task
You have a test string S. Your task is to match the string hackerrank
. This is case sensitive.
Note
This is a regex only challenge. You are not required to write code.
You only have to fill in the regex pattern in the blank (_________
).
HackerRank matching specific string solution in Cpp
#include <bits/stdc++.h> using namespace std; int main() { string s; getline(cin, s); string pattern = "hackerrank"; int count = 0, found = s.find(pattern); while(found != string::npos) { count++; found = s.find(pattern, found + 1); } cout << "Number of matches : " << count; return 0; }
HackerRank matching specific string solution in Java
public class Solution { public static void main(String[] args) { Regex_Test tester = new Regex_Test(); tester.checker("hackerrank"); } }
HackerRank matching specific string solution in Python
Regex_Pattern = r"hackerrank" # Do not delete 'r'.
HackerRank matching specific string solution in JavaScript
var Regex_Pattern = "hackerrank";
HackerRank matching specific string solution in PHP
$Regex_Pattern = "/hackerrank/"; //Do not delete '/'. Replace __________ with your regex.
Disclaimer: This problem (Matching Specific String) is generated by HackerRank but the solution is provided by Chase2learn. This tutorial is only for Educational and Learning purposes.