11/26/2019 HackerRank
2m 20s Python 3 Autocomplete Ready
left
1 #!/bin/python3 ⋯
4. Validating Email Addresses with RegEx 7
ALL
8 #
9 # Write the regular expression in the blank space below
In this question, we consider an email address in the form user@[Link] to be 10 #
valid if its domain and extension are [Link] and the value of user satisfies the 11 regularExpression = '________'
following constraints: 12 pattern = compile(regularExpression) ⋯
1
It starts with between 1 and 6 lowercase English letters denoted by the character class [a-
z].
2 The lowercase letter(s) are followed by an optional underscore, i.e. zero or one occurrence
of the _ character.
The optional underscore is followed by 0 to 4 optional digits denoted by the character
3
class [0-9].
4 Complete the code in the editor below by replacing the blank ("________") with a regular
expression that matches valid email addresses according to the criteria above. Locked
code in the editor prints True for each correct match and False for each incorrect match.
5
An example of a valid email is abcdef_1234@[Link]. It has as many of each
class of character as possible. The address a1_1@[Link] fails for two reasons.
6 First, digits cannot precede the underscore. Second, the domain fails because it is not
hackerrank.
7 Constraints
1 ≤ query ≤ 103
8
1 ≤ string length ≤ 103. Line: 7 Col: 1
9 Input Format Test Results Custom Input Run Submit Code
10
Sample Case 0
11 Sample Input 0
5
12
julia@[Link]
julia_@[Link]
13 julia_0@[Link]
julia0_@[Link]
julia@[Link]
14
Sample Output 0
15
True
True
True
False
False
Explanation 0
We perform the following query = 5 validations:
1. julia@[Link] starts with between 1 and 6 lowercase letters and contains zero of
the optional characters, so it's valid.
2. julia_@[Link] starts with between 1 and 6 lowercase letters, is followed by a
single underscore, and contains none of the optional digits, so it's valid.
3. julia_0@[Link] starts with between 1 and 6 lowercase letters, is followed by a
single underscore, and is followed by between 0 and 4 digits, so it's valid.
4. julia0_@[Link] has valid lowercase letters followed by a valid digit, but the digit
must not precede the underscore.
5. julia@[Link] has a valid user name, but its domain and extension do not
match [Link].
[Link] 1/1