0

Test string S. S must be of length, greater than or equal to 5. First char is lowercase alphabet. Second char is positive digit. Third char is not lowercase alphabet. Fourth char is not uppercase alphabet. Fifth char is uppercase alphabet.

import re

Regex_Pattern = r"^[a-z][0-9][^a-z][^A-Z][A-Z]"

print(str(bool(re.search(Regex_Pattern, input()))).lower())

Why, using this piece of code, can't I match the string: a0$?ZWe to print False instead of printing True?

3
  • Why would it print False when it matches the regex? Perhaps you meant to call lower on the input rather than on the result of str(bool(...)) ? Commented Jul 29, 2016 at 10:21
  • Actually, I want that string to be False instead of True. I mean a0$?ZWe doesn't match. My mistake. Commented Jul 29, 2016 at 10:25
  • But it does match, unless you don't consider 0 to be a positive digit. In that case change [0-9] to [1-9]. Commented Jul 29, 2016 at 10:26

1 Answer 1

1

0 is not a positive digit, yet you are matching it in your regex.

Change [0-9] to [1-9].

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.