Matching Specific String – HackerRank Solution

In this post, we will solve Matching Specific String HackerRank Solution. This problem (Matching Specific String) is a part of HackerRank Regex Series.

Objective

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

Solution – Matching Specific String – HackerRank Solution

Python

Regex_Pattern = r'hackerrank'   # Do not delete 'r'.


import re

Test_String = input()

match = re.findall(Regex_Pattern, Test_String)

print("Number of matches :", len(match))

Note: This problem (Matching Specific String) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.

Leave a Comment

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