Reputation: 3894
I want to use match all the characters in a string with a set of characters and if any of the character in string is not matching, it should not match. I am using character set and I want all the charcters in string to match character set. But in case if any additional charater is present, it passes.
How can i fix it?
>>> re.search(r'[a-z]*','abcA')
<_sre.SRE_Match object at 0x026DBBB8> ===> Should FAIL
>>> re.search(r'[a-z]*','abc')
<_sre.SRE_Match object at 0x026DBBF0>
Upvotes: 3
Views: 1773
Reputation: 8891
re.search(r'^[a-z]*$','abcA')
This will do the job. ^
implies the start of a string, while $
implies the end of a string.
Upvotes: 2