In this post, we will solve Matching Anything But a Newline HackerRank Solution. This problem (Matching Anything But a Newline) is a part of HackerRank Regex Series.
The dot (
.) matches anything (except for a newline).
Note: If you want to match (
.) in the test string, you need to escape the dot by using a slash
In Java, use
\\. instead of
You have a test string S.
Your task is to write a regular expression that matches only and exactly strings of form: abc.def.ghi.jkx, where each variable a, b, c, d, e, f, g, h, i, j, k, x can be any single character except the newline.
This is a regex only challenge. You are not required to write any code.
You only have to fill in the regex pattern in the blank (
Solution – Matching Anything But a Newline – HackerRank Solution
regex_pattern = r"^...\....\....\....$" # Do not delete 'r'. import re import sys test_string = input() match = re.match(regex_pattern, test_string) is not None print(str(match).lower())