osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE newbie question


On Apr 18, 2018 21:42, TUA <kai.peters at 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