需要在Python中选择一个格式化的字符串



因此,

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

我试图找到的id类型为ixxxxxx,其中"x"是数字,这些数字需要从一组形式为(字母)XXXXXX的id中选择。这仍然会产生误报,并且不限于六位数。有什么建议吗?

这将匹配一个包含5个字符和6位数字的字符串。

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

最新更新