I am learning python with the online book automate the boring stuff.
In chapter7 they say that the expression ^\d+$
evaluates to 'all characters must be digits' but i don't understand this. Earlier in the chapter it is said that the ^ symbol stands for (string will match if it starts with the specified character(set)) which is \d
in this case. The +
symbol means it must have one or more digits and then the dollar sign means that it should end with one or more digits. They give the following code as example.
Please see below:
wholeStringIsNum = re.compile(r'^\d+$')
wholeStringIsNum.search('1234567890')
<_sre.SRE_Match object; span=(0, 10), match='1234567890'>
wholeStringIsNum.search('12345xyz67890') == None
True
wholeStringIsNum.search('12 34567890') == None
True
Shouldn't the two expressions that evaluate to True
in the example actually be False? I mean they both start and end with one or more digits.
Please explain,
Thanks