最近在学写爬虫,聚合程序员的招聘信息,已经聚合了几个网站数据: http://www.codejob.me
但在写智联招聘爬虫的时候,薪酬如'6001-8000'
我的python代码:
s = '6001-8000'
if '-' in s:
m = re.match(r'(.*?)-(.*?)', s)
print m.group(1)
print m.group(2)
为什么m.group(1)成功得到6001,而m.group(2)得到的是空? 想请教一下大家了。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
.*?非贪婪匹配,代表任意尽可能短的字符串空字符串就可以匹配了 所以第二个
.*?匹配到的就是空字符串换用
(\d+)-(\d+)吧