简体   繁体   中英

Need to select a formatted string in Python

So,

for s in soup.findAll("tag", {"id" : re.compile('i[0-9]*')}):

The id I'm trying to find is of the type ixxxxxx where 'x' are digits and these need to be selected from a set of ids of the form (Alphabet)XXXXXX. This still gives false positives and isn't limited to six digits. Any suggestions?

this will match a string with 5 characters and 6 digits.

>>> bla = re.compile(u'^[A-Za-z]{5}\d{6}$')
>>> bla.match('abcde123456').group()
'abcde123456'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM