Your current regex doesn’t work because it tries to look for
^[A-Z]+[a-z]+[\s]+[a-z]+[\.!\?]$
: https://regex101.com/r/b96zXT/2
^[A-Z]+
: One or more capital letters at the start of the string[a-z]+
: One or more small letters after the capital letters[\s]+
: One or more whitespaces after the small letters[a-z]+
: One or more small letters after the spaces[\.!\?]+$
: One or more of the punctuations (.
,!
, or?
) after the second run of small letters, and then the string ends.
What you actually want to do:
^[A-Z][A-Za-z\s]+[\.!\?]$
https://regex101.com/r/r3CAdh/2
^[A-Z]
: Exactly one capital letter at the start of the string[A-Za-z\s]+
: One or more capital letters / small letters / spaces[\.!\?]$
: One punctuation mark at the end of the string
0
solved What is the correct regex for this exercise in python? [closed]