[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: RE newbie question
From:       Albert-Jan Roskam <sjeik_appie () hotmail ! com>
Date:       2018-04-18 19:54:23
Message-ID: AM0PR10MB196951924C66B0779D11614183B60 () AM0PR10MB1969 ! EURPRD10 ! PROD ! OUTLOOK ! COM
[Download RAW message or body]


On Apr 18, 2018 21:42, TUA <kai.peters@gmail.com> wrote:
> 
> import re
> 
> compval = 'A123456_8'
> regex = '[a-zA-Z]\w{0,7}'
> 
> if re.match(regex, compval):
> print('Yes')
> else:
> print('No')
> 
> 
> My intention is to implement a max. length of 8 for an input string. The above \
> works well in all other respects, but does allow for strings that are too long. 
> What is the proper way to fix this?

Use a $ sign at the end of the regex
-- 
https://mail.python.org/mailman/listinfo/python-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic