In this post, we will solve Matching Word & Non-Word Character HackerRank Solution. This problem (Matching Word & Non-Word Character) is a part of HackerRank Regex series.
Objective
\w
The expression \w will match any word character.
Word characters include alphanumeric characters (a–z, A–Z and 0–9) and underscores (_).
\W
\W matches any non-word character.
Non-word characters include characters other than alphanumeric characters (a–z, A–Z and 0–9) and underscore (_).
Task
You have a test string S. Your task is to match the pattern xxxXxxxxxxxxxxXxxx.
Here x denotes any word character and X denotes any non-word character.
Note
This is a regex only challenge. You are not required to write any code.
You only have to fill the regex pattern in the blank (_________
).
Solution – Matching Word & Non-Word Character – HackerRank Solution
Python
Regex_Pattern = r"\w\w\w\W\w\w\w\w\w\w\w\w\w\w\W\w\w\w" # Do not delete 'r'. import re print(str(bool(re.search(Regex_Pattern, input()))).lower())
Note: This problem (Matching Word & Non-Word Character) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.