View on GitHub

hackerrank

HackerRank personal solutions

Regex

Explore the power of regular expressions

Introduction

Name Preview Code Difficulty
Matching Specific String Match a specific string using regex. Python Easy
Matching Anything But a Newline Use [.] in the regex expression to match anything but a newline character. Python Easy
Matching Digits & Non-Digit Characters Use the expression \d to match digits and \D to match non-digit characters. Python Easy
Matching Whitespace & Non-Whitespace Character Use \s to match whitespace and \S to match non whitespace characters in this challenge. Python Easy
Matching Word & Non-Word Character Use \w to match any word and \W to match any non-word character. Python Easy
Matching Start & End Use the ^ symbol to match the start of a string, and the $ symbol to match the end characters. Python Easy

Character Class

Name Preview Code Difficulty
Matching Specific Characters Use the [ ] expression to match specific characters. Python Easy
Excluding Specific Characters Use the [^] character class to exclude specific characters. Python Easy
Matching Character Ranges Write a RegEx matching a range of characters. Python Easy

Repetitions

Name Preview Code Difficulty
Matching {x} Repetitions Match exactly x repetitions using the tool {x}. Python Easy
Matching {x, y} Repetitions Match between a range of x and y repetitions using the {x,y} tool. Python Easy
Matching Zero Or More Repetitions Match zero or more repetitions of character/character class/group using the * symbol in regex. Python Easy
Matching One Or More Repetitions Match zero or more repetitions of character/character class/group with the + symbol. Python Easy
Matching Ending Items Match the end of the string using the $ boundary matcher. Python Easy

Grouping and Capturing

Name Preview Code Difficulty
Matching Word Boundaries Using \b to match word boundaries. Python Easy
Capturing & Non-Capturing Groups Creating capturing and non-capturing group. Python Easy
Alternative Matching Matching single regex out of several regex. Python Easy

Backreferences

Name Preview Code Difficulty
Matching Same Text Again & Again Match the same text as previously matched by the capturing group. Python Easy
Backreferences To Failed Groups Backreference to a capturing group that match nothing. Python Easy
Branch Reset Groups Alternatives having same capturing group Perl Easy
Forward References Back reference to a group which appear later in regex. Java Easy

Assertions

Name Preview Code Difficulty
Positive Lookahead A positive lookahead asserts the regex to match if the regexp ahead is matching. Python Easy
Negative Lookahead It asserts the regex to match if regexp ahead is not matching. Python Easy
Positive Lookbehind It asserts the regex to match if regexp behind is matching. Python Easy
Negative Lookbehind It asserts the regex to match if regexp behind is not matching. Python Easy

Applications

Name Preview Code Difficulty
Detect HTML links Use Regular Expressions to detect links in a given HTML fragment. Python Medium
Detect HTML Tags Given N lines of HTML source, print the HTML tags found within it. Python Easy
Find A Sub-Word Use RegEx to count the number of times a sub-word appears in a given set of sentences. Python Easy
Alien Username Validate the usernames from an alien planet. Python Easy
IP Address Validation Validate possible IP Addresses with regex. Python Easy
Find a Word Find a given word in a sentence using regex special characters. Python Medium
Detect the Email Addresses Use Regular Expressions to detect the email addresses embedded in a given chunk of text. Python Medium
Detect the Domain Name Use Regular Expressions to detect domain names from a chunk of HTML Markup provided to you. Python Medium
Building a Smart IDE: Identifying comments A Text Processing Challenge. Identify the comments in program source codes. Python Medium
Detecting Valid Latitude and Longitude Pairs Can you detect the Latitude and Longitude embedded in text snippets, using regular expressions? Python Easy
HackerRank Tweets Write a regex to identify the tweets that has the string hackerrank in it Python Easy
Build a Stack Exchange Scraper Use Regular Expression to Scrape Questions from Stack Exchange. Python Easy
Utopian Identification Number Can you use regular expressions to check if the Utopian Identification Number is valid or not? Python Easy
Valid PAN format Use regex to determine the validity of a given set of characters. Python Easy
Find HackerRank Write a regex to find out if conversations start/end or both start and end with hackerrank Python Easy
Saying Hi Use a regex to print all the lines that start with “hi “ but are not immediately followed by a ‘d’ or ‘D’. Python Easy
HackerRank Language Use regex if an api request has a valid language string set or not Python Easy
Building a Smart IDE: Programming Language Detection You are provided with a set of programs in Java, C and Python and you are also told which of the languages each program is in. Now, given a program written in one of these languages, can you identify which of the languages it is written in? Python Medium
Split the Phone Numbers This problem introduces you to the concept of matching groups in regular expressions. Python Easy
Detect HTML Attributes Use Regular Expressions to detect HTML Attributes corresponding to various tags. Python Easy
The British and American Style of Spelling Use regular expression to find the count of a given word that ends with either ze or se Python Easy
UK and US: Part 2 Use regular expression to count the number of occurrences of a given word with either our or or in it. Python Easy